启用 Fusion 日志 Azure Web 作业

Enable Fusion logs Azure Web Job

我的 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 作业上启用 Fusion 吗?或者如何排查这类问题?

谢谢!

由于您已经安装了 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 的属性 window 中“详细信息”选项卡下的产品版本 属性 为 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;
};

I've a problem with an Azure Web Job, it runs locally, but it does not run on Azure.

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