VS2010 程序集加载错误

Nat*_*win 5 asp.net visual-studio-2010

当我尝试在 Visual Studio 2010 中构建 ASP.NET 4 项目时,出现以下错误:“无法加载文件或程序集 'file:///C:\Dev\project\trunk\bin\Elmah.dll'或其依赖项之一。不支持操作。(HRESULT 异常:0x80131515)”。

我已经验证该 dll 确实存在,并且已正确复制到 bin 文件夹。我还尝试删除然后重新添加对项目的引用。

仅当我将解决方案配置切换为“发布”时,构建才会失败。当解决方案配置设置为“调试”时,它不会失败。

两种配置之间的唯一区别(据我所知)显示在以下 Web.config 转换 Web.Release.config 中:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <connectionStrings>
      <add name="SqlServer" connectionString="" providerName="System.Data.SqlClient" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>
    <system.web>
        <compilation xdt:Transform="RemoveAttributes(debug)" />
        <customErrors mode="On" xdt:Transform="Replace">
            <error statusCode="404" redirect="lost.htm" />
            <error statusCode="500" redirect="uhoh.htm" />
        </customErrors>
    </system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我尝试使用 Fusion Log Viewer 来追踪程序集绑定问题,但看起来它正在正确查找并加载程序集。这是日志:

*** Assembly Binder Log Entry  (6/8/2010 @ 10:01:54 AM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\sgen.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = User
LOG: Where-ref bind. Location = C:\Dev\project\trunk\bin\Elmah.dll
LOG: Appbase = file:///c:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/bin/NETFX 4.0 Tools/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = sgen.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Attempting download of new URL file:///C:/Dev/project/trunk/bin/Elmah.dll.
LOG: Assembly download was successful. Attempting setup of file: C:\Dev\project\trunk\bin\Elmah.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Elmah, Version=1.1.11517.0, Culture=neutral, PublicKeyToken=null
LOG: Re-apply policy for where-ref bind.
LOG: Where-ref bind Codebase does not match what is found in default context. Keep the result in LoadFrom context.
LOG: Binding succeeds. Returns assembly from C:\Dev\project\trunk\bin\Elmah.dll.
LOG: Assembly is loaded in LoadFrom load context.
Run Code Online (Sandbox Code Playgroud)

我觉得我对这里到底发生了什么缺乏根本性的了解。非常感谢任何解释/帮助!

lad*_*dge 1

根据此处此处的博客,原因可能与不受信任的程序集有关。如果是这种情况,我无法想象为什么它可以在一种配置中工作而不能在另一种配置中工作,但它至少值得一看。