一段时间后,程序集FileLoadException(访问被拒绝)

时间:2010-03-15 15:44:53

标签: asp.net debugging assembly-resolution fileloadexception assemblybinding

我有一个可以正常运行一段时间(几天)的Web应用程序,然后在实例化引用外部dll的类时开始抛出FileLoadException。

  • 我没有使用任何Assembly静态方法显式加载程序集。我只是实例化一个自己从引用的库中实例化一个类的类。
  • 我运行了Process Monitor,只是监控了应用程序路径。我只得到发生错误的源代码文件的“PATH NOT FOUND”结果(在调试模式下编译,所以我假设这只是.NET尝试显示转储堆栈跟踪时发生错误的行的一部分)
  • 这是在内部专用服务器上运行的。该应用程序在.NET 3.5应用程序池上运行,另一个Web站点使用相同的引用dll构建。另一个网站有更多的流量,但从来没有出现过这个错误。
  • 应用程序在3个Web服务器之间进行负载平衡,并且所有3个在某些时候都会遇到此问题。

我打开了其中一个Web服务器上的程序集绑定日志记录。这是堆栈跟踪的样子:

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.IO.FileLoadException: Could not load file or assembly 'Project.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Access is denied.
File name: 'Project.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
   at ...
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Assembly manager loaded from:  C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable  c:\windows\system32\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = Unknown
LOG: DisplayName = Project.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/websites/ProjectPath/
LOG: Initial PrivatePath = C:\websites\ProjectPath\bin
Calling assembly : WebApp, Version=1.0.3723.37743, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\websites\ProjectPath\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/root/d77c161e/8751390/Project.Library.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/root/d77c161e/8751390/Project.Library/Project.Library.DLL.
LOG: Attempting download of new URL file:///C:/websites/ProjectPath/bin/Project.Library.DLL.
ERR: Failed to complete setup of assembly (hr = 0x80070005). Probing terminated.

   --- End of inner exception stack trace ---
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.myaccount_home_aspx.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

我对调试文件加载异常不太熟悉,所以非常感谢任何帮助(我还可以做什么来调试等)。

感谢。

2 个答案:

答案 0 :(得分:2)

可能你在Web.config中打开了模拟。如果没有真正需要假冒,请将其关闭。否则,您需要使用 C:\ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 \ Temporary ASP.NET Files 文件夹上的权限进行一些方便的操作,以允许模拟的用户访问程序集在那个文件夹中。

答案 1 :(得分:0)

当我将服务从框架2升级到框架4并启用模拟时,我遇到了同样的异常。更新客户端服务引用修复了此异常。