【问题标题】:Enable Fusion logs Azure Web Job启用融合日志 Azure Web 作业
【发布时间】:2018-03-29 06:45:06
【问题描述】:

我的 Azure Web 作业有问题,它在本地运行,但不在 Azure 上运行。问题是由于:

Unhandled Exception: System.IO.FileLoadException: Could not load file or 
assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, 
PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located 
assembly's manifest definition does not match the assembly reference. 
(Exception from HRESULT: 0x80131040) at 
Microsoft.Azure.WebJobs.ConverterManager..ctor()nat 
Microsoft.Azure.WebJobs.JobHostConfiguration..ctor(String 
dashboardAndStorageConnectionString)

我已经安装了Newtonsoft 10.0.0(某些库需要这个版本)并在 app.config 中设置了程序集重定向,但它不起作用。

您知道如何在 Azure Web 作业上启用融合吗?或者如何排查这类问题?

谢谢!

【问题讨论】:

  • 在你的错误信息中,版本是9.0,但是你说你安装的是10.0版本。您能否提供更多详细信息。
  • 显示你的代码!
  • @JanleyZhang 是的,绑定似乎无法正常工作......

标签: azure azure-webjobs azure-web-app-service


【解决方案1】:

由于您已安装 Newtonsoft.Json 10.0.x 包,因此您的项目引用属性下的 Newtonsoft.Json 版本将为 10.0.0。根据您的错误,我假设 dependentAssembly 在您的 App.config 文件中可能如下所示:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="10.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

您还需要检查您的 bin 文件夹并确保 Newtonsoft.Json.dll 属性窗口中 Details 选项卡下的 Product version 属性为 10.0.x.x。

此外,您可以尝试在 Main(string[] args) 方法下显式处理 AssemblyResolve 事件,如下所示:

AppDomain.CurrentDomain.AssemblyResolve += (sender, eventArgs) =>{
    //eventArgs.Name -> Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
    var assemblyname = eventArgs.Name.Split(',').FirstOrDefault();
    if (assemblyname.Equals("Newtonsoft.Json", StringComparison.CurrentCultureIgnoreCase))
    {
        return System.Reflection.Assembly.Load(assemblyname);

        //or just load assembly from another folder
        /*
         * string path = @"c:\temp\";
         * return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, $"{assemblyname}.dll"));
         */
    }
    return null;
};

我的 Azure Web 作业有问题,它在本地运行,但不在 Azure 上运行。

您可以利用KUDUFTP 清空您的Web Job 内容文件,然后重新部署您的WebJob 以缩小此问题的范围。如果以上试验无法解决您的问题,您最好在您的 Web Job 项目中提供packages.config,以便我们排查此问题。

【讨论】:

    猜你喜欢
    • 2019-11-02
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-07
    • 1970-01-01
    相关资源
    最近更新 更多