Azure函数“无法加载文件或程序集" [英] Azure Function "Could not load file or assembly"

查看:58
本文介绍了Azure函数“无法加载文件或程序集"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我们一直喜欢函数的所有内容,除了必须保留某些库作为Azure函数(例如某些库的更新)这一事实.Microsoft.Owin是其中之一.我们希望能够使用第4版.

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. Microsoft.Owin is one of them. We would love to be on version 4.

无法加载文件或程序集"Microsoft.Owin,版本= 2.1.0.0,区域性=中性,PublicKeyToken = 31bf3856ad364e35"或其依赖项之一.找到的程序集的清单定义与程序集引用不匹配.(来自HRESULT的异常:0x80131040)

Could not load file or assembly 'Microsoft.Owin, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

我已经尝试了所有方法,例如通过Project.json进行强制以及在整个解决方案中进行整合.在VS中进行本地调试时会发生相同的错误.因此,无论部署在本地还是本地,都在发生.

I have tried everything such as forcing via Project.json as well as consolidating across the entire solution. Locally debugging in VS same error happens. So deployed as well as local this is happening.

我们在AMQP等其他库中也遇到了类似的问题.

We get the similar issues with other libraries such as AMQP.

我们也在运行最新的SDK-Microsoft.NET.SDK.Functions版本1.0.13

We are running the latest SDK as well - Microsoft.NET.SDK.Functions version 1.0.13

推荐答案

感谢Ashokan的快速回复.我想我可能已经找到了解决这个问题的方法.

Thanks Ashokan for your fast response. I think I may have found a solution to this problem.

https://blog.slaks.net/2013-12-25/redirecting-assembly-loads-at-runtime/尤其是这篇文章: https://blog.slaks.net/2013-12-25/redirecting-assembly-loads-at-runtime/

看"npiasecki于2017年5月2日发表评论",他在那里解释.差不多就完成了,现在一切都可以工作了-在本地,通过Visual Studio调试.

Look at "npiasecki commented on May 2, 2017" and he explains there. That pretty much did the trick and all is working now - locally, debugging via 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;
}

这篇关于Azure函数“无法加载文件或程序集"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆