问题描述
RegAsm 使用 Microsoft.Bcl.Async
的 .NET 4.0 程序集失败,并带有以下消息:
'System.Threading.Tasks,Version=1.5.11.0,Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' 或其依赖项之一.
找到的程序集的清单定义与程序集引用不匹配.(来自 HRESULT 的异常:0x80131040)
我的程序集 (MyAssembly.dll
) 使用最新的 Microsoft.Bcl.Async
NuGet 包,这是项目的 packages.config
:
<?xml version="1.0" encoding="utf-8"?><包><package id="Microsoft.Bcl" 版本="1.1.6" targetFramework="net40"/><包 id="Microsoft.Bcl.Async" 版本="1.0.165" targetFramework="net40"/><package id="Microsoft.Bcl.Build" 版本="1.0.13" targetFramework="net40"/></包>
它捆绑了 System.Threading.Tasks.dll
版本:2.6.6.0,它是 NuGet 包的一部分.目标系统(带有 .NET 4.0 但没有 .NET 4.5 的 Win7)上没有其他 System.Threading.Tasks.dll
,在 GAC 或其他任何地方都没有.
这里是 MyAssembly.dll.config
,它有正确的 System.Threading.Tasks
的 bindingRedirect
元素:
<?xml version="1.0" encoding="utf-8"?><配置><运行时><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><依赖程序集><assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a"culture="neutral"/><bindingRedirect oldVersion="0.0.0.0-2.6.6.0" newVersion="2.6.6.0"/></dependentAssembly><依赖程序集><assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a"culture="neutral"/><bindingRedirect oldVersion="0.0.0.0-2.6.6.0" newVersion="2.6.6.0"/></dependentAssembly><依赖程序集><assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a"culture="neutral"/><bindingRedirect oldVersion="0.0.0.0-2.6.6.0" newVersion="2.6.6.0"/></dependentAssembly></assemblyBinding></运行时></配置>
我的问题:RegAsm 不使用 MyAssembly.dll.config
吗?如何使其工作以解决 bindingRedirect
指令?
我想出的解决方案是 hack:
从
C:WindowsMicrosoft.NETFrameworkv4.0.30319RegAsm 复制了
到RegAsm.exe
和RegAsm.exe.config
.exeMyAssembly.dll
所在的本地文件夹;将
RegAsm.exe.config
编辑为如下所示:
<?xml 版本="1.0"?><配置><启动使用LegacyV2RuntimeActivationPolicy="true"><requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/><supportedRuntime version="v4.0" sku="client"/></启动><运行时><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><依赖程序集><assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a"culture="neutral"/><bindingRedirect oldVersion="0.0.0.0-2.6.6.0" newVersion="2.6.6.0"/></dependentAssembly><依赖程序集><assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a"culture="neutral"/><bindingRedirect oldVersion="0.0.0.0-2.6.6.0" newVersion="2.6.6.0"/></dependentAssembly><依赖程序集><assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a"culture="neutral"/><bindingRedirect oldVersion="0.0.0.0-2.6.6.0" newVersion="2.6.6.0"/></dependentAssembly></assemblyBinding></运行时></配置>
- 现在,运行
RegAsm.exe/codebase MyAssembly.dll
可以正常运行.
有趣的是,useLegacyV2RuntimeActivationPolicy="true"
已经存在于标准 RegAsm.exe.config
中,但仅此一项并没有帮助.
我认为这与此处报告的错误相同:https://connect.microsoft.com/VisualStudio/feedback/details/789318/asyncpack-system-io-fileloadexception-could-not-load-file-or-assembly-system-threading-tasks-version-1-5-11-0.
RegAsm failing for a .NET 4.0 assembly using Microsoft.Bcl.Async
with the following message:
RegAsm : error RA0000 : Could not load file or assembly
'System.Threading.Tasks, Version=1.5.11.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
The located assembly's manifest definition does not match
the assembly reference. (Exception from HRESULT: 0x80131040)
My assembly (MyAssembly.dll
) uses the latest Microsoft.Bcl.Async
NuGet package, here's the project's packages.config
:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl" version="1.1.6" targetFramework="net40" />
<package id="Microsoft.Bcl.Async" version="1.0.165" targetFramework="net40" />
<package id="Microsoft.Bcl.Build" version="1.0.13" targetFramework="net40" />
</packages>
It bundles System.Threading.Tasks.dll
Version: 2.6.6.0 which is a part of that NuGet package. There is no other System.Threading.Tasks.dll
on the target system (Win7 with .NET 4.0 but without .NET 4.5), neither in GAC nor anywhere else.
Here is MyAssembly.dll.config
, it has correct bindingRedirect
elements for System.Threading.Tasks
:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.6.0" newVersion="2.6.6.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.6.0" newVersion="2.6.6.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.6.0" newVersion="2.6.6.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
My question: does RegAsm not use MyAssembly.dll.config
? How do I make it work so it resolves bindingRedirect
instructions?
The solution I have come up with is a hack:
copied
RegAsm.exe
andRegAsm.exe.config
fromC:WindowsMicrosoft.NETFrameworkv4.0.30319RegAsm.exe
to a local folder whereMyAssembly.dll
is;edited
RegAsm.exe.config
to look like this:
<?xml version ="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/>
<supportedRuntime version="v4.0" sku="client" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.6.0" newVersion="2.6.6.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.6.0" newVersion="2.6.6.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.6.0" newVersion="2.6.6.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
- now, running
RegAsm.exe /codebase MyAssembly.dll
works fine as expected.
Interestingly, useLegacyV2RuntimeActivationPolicy="true"
has already been there in the standard RegAsm.exe.config
, but alone it did not help.
I think this is the same bug reported here: https://connect.microsoft.com/VisualStudio/feedback/details/789318/asyncpack-system-io-fileloadexception-could-not-load-file-or-assembly-system-threading-tasks-version-1-5-11-0.
这篇关于使用 Microsoft.Bcl.Async 的 .NET 4.0 程序集的 RegAsm 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!