简体   繁体   English

Azure功能“无法加载文件或程序集”

[英]Azure Function “Could not load file or assembly”

So we have been loving everything about functions except the fact that we have to keep certain libraries behind as Azure Functions like the idea of certain libraries updating. 因此,我们一直喜欢函数方面的所有内容,除了必须保留某些库作为Azure函数(例如某些库的更新)这一事实。 Microsoft.Owin is one of them. Microsoft.Owin是其中之一。 We would love to be on version 4. 我们希望使用第4版。

Could not load file or assembly 'Microsoft.Owin, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. 无法加载文件或程序集“ Microsoft.Owin,版本= 2.1.0.0,文化=中性,PublicKeyToken = 31bf3856ad364e35”或其依赖项之一。 The located assembly's manifest definition does not match the assembly reference. 找到的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040) (来自HRESULT的异常:0x80131040)

I have tried everything such as forcing via Project.json as well as consolidating across the entire solution. 我已经尝试了所有方法,例如通过Project.json进行强制以及在整个解决方案中进行整合。 Locally debugging in VS same error happens. 在VS中进行本地调试时会发生相同的错误。 So deployed as well as local this is happening. 因此,无论是在本地部署,还是在发生。

We get the similar issues with other libraries such as AMQP. 我们在其他库(例如AMQP)中也遇到了类似的问题。

We are running the latest SDK as well - Microsoft.NET.SDK.Functions version 1.0.13 我们也在运行最新的SDK-Microsoft.NET.SDK.Functions版本1.0.13

Possible duplicate of the following question. 以下问题的可能重复。

Azure Functions - Could not load file or assembly ''Microsoft.WindowsAzure.Storage' Azure函数-无法加载文件或程序集'Microsoft.WindowsAzure.Storage'

Try to find whether Owin is native library of Azure functions or not. 尝试查找Owin是否是Azure函数的本机库。 If yes, you can refer it directly. 如果是,则可以直接引用。 #r "Library.Namspace". #r“ Library.Namspace”。 Otherwise, you need to follow the suggestions in above thread. 否则,您需要遵循上述线程中的建议。

Thanks Ashokan for your fast response. 感谢Ashokan的快速回复。 I think I may have found a solution to this problem. 我想我可能已经找到了解决这个问题的方法。

https://blog.slaks.net/2013-12-25/redirecting-assembly-loads-at-runtime/ Rather in particular this post : https://blog.slaks.net/2013-12-25/redirecting-assembly-loads-at-runtime/ https://blog.slaks.net/2013-12-25/redirecting-assembly-loads-at-runtime/特别是这篇文章: https : //blog.slaks.net/2013-12-25/redirecting-运行时的程序集加载/

Look at "npiasecki commented on May 2, 2017" and he explains there. 看“ npiasecki于2017年5月2日发表评论”,他在那里解释。 That pretty much did the trick and all is working now - locally, debugging via Visual Studio. 这几乎可以解决问题,并且现在都可以正常工作-在本地通过Visual Studio进行调试。

 private static void ConfigureBindingRedirects()
{
   BindingRedirect.RedirectAssembly("Microsoft.Owin", new Version("4.0.0"), "31bf3856ad364e35");

}

private static void RedirectAssembly(
    string shortName,
    Version targetVersion,
    string publicKeyToken)
{
    ResolveEventHandler handler = null;

    handler = (sender, args) =>
    {
        var requestedAssembly = new AssemblyName(args.Name);

        if (requestedAssembly.Name != shortName)
        {
            return null;
        }

        var targetPublicKeyToken = new AssemblyName("x, PublicKeyToken=" + publicKeyToken)
            .GetPublicKeyToken();
        requestedAssembly.Version = targetVersion;
        requestedAssembly.SetPublicKeyToken(targetPublicKeyToken);
        requestedAssembly.CultureInfo = CultureInfo.InvariantCulture;

        AppDomain.CurrentDomain.AssemblyResolve -= handler;

        return Assembly.Load(requestedAssembly);
    };

    AppDomain.CurrentDomain.AssemblyResolve += handler;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure Function异常无法加载ActiveDirectory文件或程序集 - Azure Function exception could not load ActiveDirectory file or assembly Azure Function:无法加载文件或程序集 Newtonsoft.Json - Azure Function: Could not load file or assembly Newtonsoft.Json Azure WebJob失败:无法加载文件或程序集 - Azure WebJob fails: Could not load file or assembly “无法加载文件或程序集” azure Web应用程序 - “Could Not load file or assembly” azure web appl Azure 函数,无法加载文件或程序集 - Azure Functions, Could not load file or assembly 无法加载文件或程序集... Windows Azure 网站 - Could not load file or assembly… Windows Azure Website 无法在 Azure Function v2 中加载文件或程序集“System.Private.ServiceModel” - Could not load file or assembly 'System.Private.ServiceModel' in Azure Function v2 使用 Gembox.Document 的 azure 函数中出现“无法加载文件或程序集‘PresentationCore’”错误 - "Could not load file or assembly 'PresentationCore'" error in azure function using Gembox.Document Azure Function 无法加载文件或程序集“System.Security.Cryptography.Pkcs” - Azure Function Could not load file or assembly 'System.Security.Cryptography.Pkcs' Azure Function:System.Private.CoreLib:无法加载文件或程序集“System.ComponentModel.Annotations...” - Azure Function: System.Private.CoreLib: Could not load file or assembly 'System.ComponentModel.Annotations…'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM