.net 使用已签名程序集会导致TargetInvestment异常

.net 使用已签名程序集会导致TargetInvestment异常,.net,reflection,deployment,assemblies,signed,.net,Reflection,Deployment,Assemblies,Signed,为了使SQL CLR程序集在不安全模式下工作,我必须使用密钥对程序集进行签名。我的解决方案中的另一个项目引用该程序集以使用其某些功能。在运行时期间,当对已签名程序集中的函数进行调用时,将引发TargetInvocationException,并显示以下消息: 无法加载文件或程序集“MyAssembly,Version=12.2.1.3,Culture=neutral,PublicKeyToken=null”或其依赖项之一。定位的程序集清单定义与程序集引用不匹配。来自HRESULT的异常:0x80

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

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

有没有办法让.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.
谢谢

PublicKeyToken=null


它正在查找没有强名称的程序集。您需要更新程序集引用删除并再次添加它,然后重新生成项目。

这不是因为您的项目对MyAssembly的引用与excepton消息所示的已签名程序集的清单不匹配吗?我已删除/读取了引用,现在消息略有不同:{无法加载文件或程序集'MyAssembly,版本=1.2.3.4,区域性=neutral,PublicKeyToken=5ad1afbaab228075'或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。HRESULT中的异常:0x8013100:MyAssembly,版本=1.2.3.4,区域性=neutral,PublicKeyToken=5ad1afbaab228075}。但是,当我使用ildasm检查主dll时,MyAssembly有一个不同的PublicKeyToken!好吧,这也行不通。请确保引用程序集文件与运行时加载的文件相同。Fuslogvw.exe可以帮助记录所有绑定。