使用签名程序集会导致TargetInvocationException

时间:2011-09-22 12:58:25

标签: .net reflection deployment assemblies signed

为了让SQL CLR程序集在UNSAFE模式下工作,我不得不用密钥对程序集进行签名。我的解决方案中的另一个项目引用该程序集来使用它的一些功能。在运行时期间,当对已签名程序集内的函数进行调用时,将抛出TargetInvocationException,并显示以下消息:

  

无法加载文件或程序集“MyAssembly,Version = 12.2.1.3,Culture = neutral,PublicKeyToken = null”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。 (HRESULT异常:0x80131040)

有没有办法让.NET加载正确的程序集/通过异常? 编辑: 在主程序集上运行fusion之后,它似乎每次尝试使用不同的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.

谢谢!

1 个答案:

答案 0 :(得分:0)

  

公钥=空

正在寻找一个没有强名的集会。您需要更新程序集引用(删除并重新添加)并重新构建项目。