简体   繁体   English

解决 Azure 应用服务中的 .NET TypeLoadExceptions

[英]Resolving .NET TypeLoadExceptions in Azure App Service

I have an Azure App Service where I published my .NET application (.NET Framework 4.7.2).我有一个 Azure 应用服务,我在其中发布了我的 .NET 应用程序(.NET Framework 4.7.2)。 The application works fine on local Visual Studio IIS Express.该应用程序在本地 Visual Studio IIS Express 上运行良好。

When I run it in the App Service I get TypeLoadExceptions.当我在应用服务中运行它时,我得到 TypeLoadExceptions。 The interesting parts are, for example, these errors:例如,有趣的部分是这些错误:

    - System.IO.FileLoadException: Could not load file or assembly 'EPiServer.Forms, Version=3.0.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'EPiServer.Forms, Version=3.0.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7'

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Now, in any virtual server case I could just enable the EnableLog registry value and see more about what dependency I am missing.现在,在任何虚拟服务器情况下,我都可以启用 EnableLog 注册表值并查看有关我缺少的依赖项的更多信息。 I tried to change the registry value thru PowerShell but got access denied.我试图通过 PowerShell 更改注册表值,但访问被拒绝。 I haven't found any Fusion Log viewer in Azure either.我也没有在 Azure 中找到任何 Fusion Log 查看器。

What is the correct way to debug Assembly binding errors in Azure App Service?在 Azure 应用服务中调试程序集绑定错误的正确方法是什么?

Browsing through this: How to enable assembly bind failure logging (Fusion) in .NET but it does not say anything about doing it in Azure App Service.浏览此内容: 如何在 .NET 中启用程序集绑定失败日志记录 (Fusion),但它没有说明在 Azure 应用服务中执行此操作。

There is no way to get Fusion logging in Azure App service now.现在无法在 Azure 应用服务中获取 Fusion 日志记录。 Because it's required to modify registry to enable it.因为需要修改注册表才能启用它。 But modifying registry is not allowed in Azure App Service.但是在 Azure 应用服务中不允许修改注册表。 Refer to here for more info.请参阅此处了解更多信息。

The error "The located assembly's manifest definition does not match the assembly reference."错误“定位的程序集的清单定义与程序集引用不匹配。” usually means the assembly the runtime finds does not match that you specified in application.通常意味着运行时找到的程序集与您在应用程序中指定的程序集不匹配。

In Azure web app, you can check the dll via FTP.在 Azure Web 应用程序中,您可以通过 FTP 检查 dll。 Check " Accessing files via ftp ".选中“ 通过 ftp 访问文件”。 The dlls usually locates in \\wwwroot\\bin . dll 通常位于\\wwwroot\\bin Confirm the dll info matches the dll you use in the solution.确认 dll 信息与您在解决方案中使用的 dll 匹配。 You may check web.config and package.config whether you specified different version for this assembly.您可以检查 web.config 和 package.config 是否为此程序集指定了不同的版本。

Also refer to here to understand how .net runtime locates dll.另请参阅此处以了解 .net 运行时如何定位 dll。

Just wanted to post an update to say that Fusion logging on an Azure App service can now be enabled, there's an article on it here .只是想发布一个更新的说,在一个蓝色的应用服务融合日志现在可以启用,有关于它的文章在这里

Basically all you have to do is add an application setting called WEBSITE_FUSIONLOGGING_ENABLED and set it to 1.基本上,您要做的就是添加一个名为 WEBSITE_FUSIONLOGGING_ENABLED 的应用程序设置并将其设置为 1。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM