2011-09-22 60 views
1

爲了讓SQL CLR程序集在UNSAFE模式下工作,我必須使用密鑰對程序集簽名。我的解決方案中的另一個項目引用該程序集以使用其某些功能。在運行時,當一個簽名的程序集內的函數調用時,一個TargetInvocationException拋出以下消息:使用簽名的程序集會導致TargetInvocationException

Could not load file or assembly 'MyAssembly, Version=12.2.1.3, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

有沒有辦法有.NET加載正確的裝配/擦肩而過異常? 編輯: 在主程序集上運行融合後,它似乎嘗試每次使用不同的publickeytoken加載MyAssembly兩次。第一次加載成功,但第二次加載失敗。錯誤消息引用失敗的加載的publickeytoken。爲什麼試圖做兩次? 以下是錯誤文本:

The operation failed. 
Bind result: hr = 0x80131040. No description available. 

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll 
Running under executable C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\WebDev.WebServer20.exe 
--- A detailed error log follows. 

=== Pre-bind state information === 
LOG: DisplayName = MyAssembly, Version=12.3.2.148, Culture=neutral, PublicKeyToken=5ad1afbaab228075 
(Fully-specified) 
LOG: Appbase = file:///C:/inetpub/wwwroot/MySolution converted to 2010/MyApplication/ 
LOG: Initial PrivatePath = C:\inetpub\wwwroot\MySolution converted to 2010\MyApplication\bin 
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\8365e84e 
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\8365e84e 
LOG: AppName = d8cf427a 
Calling assembly : (Unknown). 
LOG: This bind starts in default load context. 
LOG: Using application configuration file: C:\inetpub\wwwroot\MySolution converted to 2010\MyApplication\web.config 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config. 
LOG: Post-policy reference: MyAssembly, Version=12.3.2.148, Culture=neutral, PublicKeyToken=5ad1afbaab228075 
LOG: GAC Lookup was unsuccessful. 
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/root/8365e84e/d8cf427a/MyAssembly.DLL. 
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/root/8365e84e/d8cf427a/MyAssembly/MyAssembly.DLL. 
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/MySolution converted to 2010/MyApplication/bin/MyAssembly.DLL. 
LOG: Assembly download was successful. Attempting setup of file: C:\inetpub\wwwroot\MySolution converted to 2010\MyApplication\bin\MyAssembly.dll 
LOG: Entering download cache setup phase. 
LOG: Assembly Name is: MyAssembly, Version=12.3.2.148, Culture=neutral, PublicKeyToken=7a45b8ac095ea0f9 
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN 
ERR: The assembly reference did not match the assembly definition found. 
ERR: Setup failed with hr = 0x80131040. 
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated. 

謝謝!

+0

是不是因爲您的項目對MyAssembly的引用與您簽名的程序集的清單不匹配,因爲excepton消息提示? –

回答

0

PublicKeyToken=null

它正在尋找沒有強名的組件。您需要更新程序集引用(刪除並再次添加)並重建項目。

+0

我已經刪除/閱讀了引用,現在消息略有不同:{「無法加載文件或程序集'MyAssembly,Version = 1.2.3.4,Culture = neutral,PublicKeyToken = 5ad1afbaab228075'或它的一個依賴項。清單定義與程序集引用不匹配(來自HRESULT的異常:0x80131040)「:」MyAssembly,Version = 1.2.3.4,Culture = neutral,PublicKeyToken = 5ad1afbaab228075「}。但是,當我使用ildasm檢查主DLL時,MyAssembly具有不同的PublicKeyToken! – laconicdev

+0

那麼,那也不行。確保引用程序集文件與運行時加載的文件*相同*。 Fuslogvw.exe可以幫助,記錄所有綁定。 –

相關問題