【发布时间】:2015-01-25 19:00:15
【问题描述】:
我一直在尝试将一个新的 asp.net mvc 项目部署到 Azure 进行生产。一切都在本地工作,但我在部署时遇到了程序集问题。
在导航到大多数页面时,我开始收到以下错误:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
使用来自https://stackoverflow.com/a/8824250/1411764的信息我发现了异常:
Could not load file or assembly 'Microsoft.Web.Administration,
Version=7.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or
one of its dependencies. The system cannot find the file specified.
Microsoft.Web.Administration 似乎是一个 IIS 程序集。
然后我使用Nuget 将Microsoft.Web.Administration 添加到项目中。
现在我遇到了一个新错误:
Could not load file or assembly 'Microsoft.Web.Administration' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
我尝试在 web.config 中添加绑定重定向
<dependentAssembly>
<assemblyIdentity name="Microsoft.Web.Administration" publicKeyToken="31BF3856AD364E35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.9.0.0" newVersion="7.9.0.0" />
此时它会立即中断,我无法加载任何页面。 (似乎比我没有额外的 dll 时更糟糕。
我已经阅读了许多类似的帖子,但似乎无法弄清楚。希望由于对 Azure 缺乏了解,我做错了一些简单的事情。任何帮助将不胜感激。
更新信息
右键属性供参考Microsoft.Web.Administration:
复制本地:真
运行时版本 v2.0.50727
版本:7.0.0.0
调用程序集:Microsoft.WebMatrix.Core,Version=8.1.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35
更新 2 - 来自 cmets:
在设置绑定到7.0.0.0 后,它现在在服务器上再次编译并可以显示一些页面,但我仍然遇到以前的错误。
Could not load file or assembly 'Microsoft.Web.Administration, Version=7.9.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)
据此推测,Nuget 仅提供了版本 7.0.0.0,但有人认为它需要 7.9.0.0。
更新 3:成功
我开始研究版本号差异,发现 stack question 解释了 IIS 和 IISExpress 之间的一些差异。
现在我将重定向从7.9.0.0 更改为7.0.0.0,这似乎解决了这个问题。
<bindingRedirect oldVersion="0.0.0.0-7.9.0.0" newVersion="7.0.0.0" />
程序集现在可以工作并且页面都在加载。
不过,这个解决方案感觉很hacky。绑定到较低版本是不好的做法还是将来可能会导致问题?我担心我应该解决调用不同 IIS 版本的代码。
【问题讨论】:
-
是 Web 角色还是网站?
-
您能否检查该 Microsoft.Web.Administration.dll 的 FileInfo 并添加该 dll 的 AssemblyInfo 和文件版本,我怀疑它们可能不匹配 100%。
-
尝试启用 Fusion 日志以获取有关精确绑定问题的更多信息stackoverflow.com/questions/4679279/…
-
此链接显示了启用 fusino 日志记录的更好方法stackoverflow.com/questions/255669/…
-
如果 Visual Studio 声称版本实际上是
7.0.0,为什么bindingRedirect指向7.9.0.0?
标签: asp.net-mvc azure .net-assembly