【问题标题】:Assembly FileLoadException (Access is denied) after period of time一段时间后的程序集 FileLoadException(访问被拒绝)
【发布时间】:2012-10-10 15:23:53
【问题描述】:

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

  • 我没有使用任何程序集静态方法显式加载程序集。我只是在实例化一个类,它本身会从引用的库中实例化一个类。
  • 我运行了 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)

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

谢谢。

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 更新客户端服务是什么意思?我有这个问题,我想要模仿。我正在处理的应用程序是 SQL Server Reporting Services(没有简单的 IIS 配置,自包含,需要配置文件进行配置)。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-27
      • 1970-01-01
      • 2013-05-26
      • 2016-02-25
      • 2016-12-15
      • 1970-01-01
      • 2017-06-29
      相关资源
      最近更新 更多