为什么我得到System.IO.FileLoadException:无法加载文件或程序集,大约每周一次在我的ASP.Net网站上?

我有一个相当简单的内部ASP.Net网站,每周大约加载一次Microsoft.Practices.EnterpriseLibrary.Data dll。 这是Exception消息:

System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Access is denied. File name: 'Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' at foobar.Intranet.Logic.Data.UserDB.SelectByUserName(String userName) at foobar.Intranet.Logic.Info.User.ValidateUser(String userName) in F:\Development\foobar\foobar\foobar.Intranet.Logic\Info\User.cs:line 130 at Login.ValidateUser(String username, String password) in e:\foobar\foobar.Intranet\Login.aspx.cs:line 32 === Pre-bind state information === LOG: User = Unknown LOG: DisplayName = Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null (Fully-specified) LOG: Appbase = file:///E:/foobar/foobar.Intranet/ LOG: Initial PrivatePath = E:\foobar\foobar.Intranet\bin Calling assembly : foobar.Intranet.Logic, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. === LOG: This bind starts in default load context. LOG: Using application configuration file: E:\foobar\foobar.Intranet\web.config LOG: Using host configuration file: \\?\C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet.config LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/foobar.intranet/668896d8/82d7e51c/Microsoft.Practices.EnterpriseLibrary.Data.DLL. LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/foobar.intranet/668896d8/82d7e51c/Microsoft.Practices.EnterpriseLibrary.Data/Microsoft.Practices.EnterpriseLibrary.Data.DLL. LOG: Attempting download of new URL file:///E:/foobar/foobar.Intranet/bin/Microsoft.Practices.EnterpriseLibrary.Data.DLL. ERR: Failed to complete setup of assembly (hr = 0x80070005). Probing terminated. 

注意事项:

  • 一个简单的IIS重置修复了这个问题。
  • 我们在单个Web服务器上运行相同的代码,没有任何问题。 然后,我们将站点移动到两个新的负载平衡(使用粘性会话)Web服务器(所有三个Windows Server 2003 R2 Standard Edition SP1)。 现在,每个负载均衡的Web服务器每周一次就抛出这个exception。
    • 我能想到的唯一主要区别是,我已经在负载均衡服务器上安装了4.0 .NET框架。 该网站仍然在ASP.NET 2.0下运行,所以我不知道这将是一个什么问题
  • 我已将索引服务配置为不搜索“Temporary ASP.NET Files”文件夹,但它没有帮助。
  • 我们在我们的网站上使用Microsoft.Practices.EnterpriseLibrary.Data dll。 几乎每一页都使用我们的逻辑DLL,而后者又使用EnterpriseLibrary dll。
  • 虽然发生了一次错误,但我甚至想看看哪些进程在“Temporary ASP.NET Files”文件夹中锁定了dll,并且它与服务器上的锁没有任何不同。
  • 一旦错误开始,它每次都会出错,直到执行iisreset

任何人都可以提供的见解将非常感激。 如果我错过了什么,请告诉我。

谢谢!

看看Assembly Binding Log Viewer 。 它可能会指向正确的方向。

我快速浏览了其他SO答案,并且有人建议应用程序可能是针对DLL的签名版本开发的,但生产运行时只能访问未签名的版本。 看起来您的生产正在加载无符号程序集( PublicKeyToken=null )。

安装以下nuget包:

安装包log4net -Version 2.0.0安装包linqtoexcel

Install-Package System.Data.Sqlite.x86 -Version 1.0.88.0 Install-Package ServiceStack -Version 3.9.71 Install-Package ServiceStack.OrmLite.Sqlite32 -Version 3.9.71