1

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

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

我在其中一台 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)

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

谢谢。

4

2 回答 2

2

可能您在 Web.config 中打开了模拟。如果真的不需要模拟,请将其关闭。否则,您将需要使用C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files 文件夹的权限做一些方便的技巧,以允许您的模拟用户访问该文件夹中的程序集。

于 2010-07-16T09:32:31.630 回答
0

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

于 2012-10-10T07:23:53.497 回答