Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
640 views
in Technique[技术] by (71.8m points)

c# - RegAsm failing for a .NET 4.0 assembly using Microsoft.Bcl.Async

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The solution I have come up with is a hack:

  • copied RegAsm.exe and RegAsm.exe.config from C:WindowsMicrosoft.NETFrameworkv4.0.30319RegAsm.exe to a local folder where MyAssembly.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...