2010-06-08 68 views
4

當我嘗試在Visual Studio 2010中生成ASP.NET 4項目時出現以下錯誤:「無法加載文件或程序集」文件:/// C:\ Dev \ project \ trunk \ bin \ Elmah.dll'或它的一個依賴項,操作不受支持(來自HRESULT的異常:0x80131515)「。VS2010程序集加載錯誤

我已經驗證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> 

我已經使用融合日誌查看器來跟蹤嘗試程序集綁定問題,但它看起來像正在查找並加載程序集。這裏是日誌:

*** 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. 

我覺得我有一個根本的缺乏理解,在這裏究竟是怎麼回事。任何解釋/幫助非常感謝!

+0

0x80131515是COR_E_NOTSUPPORTED,即某事正在拋出一個NotSupportedException。但是,瀏覽Elmah源代碼時除了包含的程序集外,沒有對NotSupportedException的引用: -/ – Rup 2010-06-08 16:30:10

+0

在我看來,這可能是Visual Studio 2010問題。但是,這當然只是一個猜測。關閉尋找解決方法! – 2010-06-08 16:45:19

回答

1

根據博客herehere,原因可能與未受信任的程序集有關。如果是這種情況,我無法想象爲什麼它能在一種配置下工作,而不是在另一種配置下工作,但至少應該看一些東西。

+0

是的,我看到了那些帖子,但這似乎不是問題。我已經嘗試重新下載Elmah dll並在整個過程中進行,但它們似乎沒有被「封鎖」。儘管在第一個博客上發表評論的人(http://cantgrokwontgrok.blogspot.com/2009/10/visual-studio-unknown-build-error.html?showComment=1264721898924#c2352316767675997414)似乎正在經歷精確的同樣的問題。 – 2010-06-08 16:43:36

1

我意識到這是一個稍遲的回覆,但我剛剛在發佈模式中經歷並修復了與Elmah完全相同的問題(和OP一樣,調試模式工作正常)。

我通過在Windows資源管理器中修改Elmah.dll的屬性解決了我的問題 - 從常規選項卡中,我必須單擊解除阻止來說服探險家文件確實安全。之後,發佈模式發佈工作正常。

+0

現在重溫這個 - 感謝提醒!回到我遇到這個問題時,我確實檢查了文件是否被阻止(不是)。自從我開始使用NuGet將Elmah帶入我的項目之後,我從未遇到過這個問題。我會提出這個答案,但我仍然不知道問題的根本原因是什麼。所以我想我會更多地將它歸類爲解決方法。 – 2011-09-01 18:39:58

3

可能爲時已晚,我遇到過這個問題。在我的情況下,我修復了以下說明,我在評論中發現(謝謝托馬斯!)this post

在'開發人員IT'評論中談到在app.config中做同樣的事情。其實一定要在別的地方。按照後面的說明。


更好的解決方案是「修復」微軟的sgen發行版。首先找到sgen(例如,在我的系統上爲.Net 4.0,它位於「C:\ Program Files \ Microsoft SDKs \ Windows \ v7.0A \ bin \ NETFX 4.0 Tools」中。)接下來,創建文件sgen.exe。配置與內容:

<configuration> 
    <runtime> 
    <loadFromRemoteSources enabled="true" /> 
    </runtime> 
</configuration> 

的點,將在SGEN應用程序配置文件設置爲true loadFromRemoteResources允許SGEN正確地從ClearCase的卷加載文件。我知道。我遇到了同樣的問題,這是我如何解決它。

請注意,在某些時候,Microsoft可能會創建應用程序配置文件,因此如果您這樣做,請首先檢查文件是否已經存在,如果存在,請檢查它是否仍需要該設置。


0

問題可能有多種原因。

出現加載混合模式程序集時暴露(在「ANY_CPU」和「X86」模式下進行編譯。)

我修改了編譯選項爲我的主程序「X86」相匹配的假設模式組件DLL。問題消失了。

它可能與加載dll文件的順序有關。

相關問題