为了使SQL CLR程序集在不安全模式下工作,我必须使用密钥对程序集进行签名。我的解决方案中的另一个项目引用该程序集以使用其某些功能。在运行时期间,当对签名程序集中的函数进行调用时,将抛出TargetInvocationException并带有以下消息:
无法加载文件或程序集'MyAssembly, Version=12.2.1.3,文化=neutral, PublicKeyToken=null'或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(Exception from HRESULT: 0x80131040)
是否有一种方法可以让。net加载正确的程序集/通过传递异常?编辑:在主程序集上运行fusion之后,它似乎每次都试图用不同的publickeytoken加载MyAssembly两次。第一次加载成功,但第二次加载失败。错误消息引用失败加载的publickeytoken。为什么要做两次呢?下面是错误的文本:
The operation failed.
Bind result: hr = 0x80131040. No description available.
Assembly manager loaded from: C:WindowsMicrosoft.NETFrameworkv2.0.50727mscorwks.dll
Running under executable C:Program Files (x86)Common FilesMicrosoft SharedDevServer10.0WebDev.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:inetpubwwwrootMySolution converted to 2010MyApplicationbin
LOG: Dynamic Base = C:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Filesroot8365e84e
LOG: Cache Base = C:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Filesroot8365e84e
LOG: AppName = d8cf427a
Calling assembly : (Unknown).
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:inetpubwwwrootMySolution converted to 2010MyApplicationweb.config
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv2.0.50727configmachine.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:inetpubwwwrootMySolution converted to 2010MyApplicationbinMyAssembly.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.
谢谢!
都空
查找没有强名称的程序集。您需要更新程序集引用(删除并再次添加它)并重新构建项目。