解决Azure中COULD NOT LOAD FILE OR ASSEMBLY问题

当把Web项目部署到Azure的时候,有时候会出现COULD NOT LOAD FILE OR ASSEMBLY的问题。这样问题一般是由于某些依赖的Assembly的版本不对导致的,例如在开发机上可能同时安装了MVC 3和MVC4。那么开发机不会出现问题,因为可以找到相应的Assembly。但是部署到Azure后就出现了依赖文件的问题。例如问题如下:

"COULD NOT LOAD FILE OR ASSEMBLY 'SYSTEM.WEB.WEBPAGES, VERSION=2.0.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)"
Could not load file or assembly 'System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. 

如果你登录到Azure的机器,然后修改注册表HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion!EnableLog] (DWORD) to 1

你可以看到更详细的信息,例如如下:

=== Pre-bind state information ===
LOG: User = NT AUTHORITY\NETWORK SERVICE
LOG: DisplayName = System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///E:/sitesroot/1/
LOG: Initial PrivatePath = E:\sitesroot\1\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: E:\sitesroot\1\web.config
LOG: Using host configuration file: D:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from D:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///D:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/sts/5c2051b2/ac0bf06b/System.Web.Helpers.DLL.
LOG: Attempting download of new URL file:///D:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/sts/5c2051b2/ac0bf06b/System.Web.Helpers/System.Web.Helpers.DLL.
LOG: Attempting download of new URL file:///E:/sitesroot/1/bin/System.Web.Helpers.DLL.
LOG: Attempting download of new URL file:///E:/sitesroot/1/bin/System.Web.Helpers/System.Web.Helpers.DLL.
LOG: Attempting download of new URL file:///D:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/sts/5c2051b2/ac0bf06b/System.Web.Helpers.EXE.
LOG: Attempting download of new URL file:///D:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/sts/5c2051b2/ac0bf06b/System.Web.Helpers/System.Web.Helpers.EXE.
LOG: Attempting download of new URL file:///E:/sitesroot/1/bin/System.Web.Helpers.EXE.
LOG: Attempting download of new URL file:///E:/sitesroot/1/bin/System.Web.Helpers/System.Web.Helpers.EXE.

 

解决方法查找项目的References下面各个Assembly,查找其版本

image

如果版本用错了,那么需要重新引用正确的版本。

如果Azure上没有安装支持的库或者runtime,需要把Copy Local修改成True,这样dll就一并打包到Azure的package中。

image

 

有时候这些问题很难查,最好也是最花时间的方式是把整个包拉下来,通过ILSpy等工具查依赖项,细心仔细一个个查。



    本文转自Jake Lin博客园博客,原文链接:http://www.cnblogs.com/procoder/archive/2013/01/10/Azure-COULD-NOT-LOAD-FILE-OR-ASSEMBLY.html,如需转载请自行联系原作者


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值