RegAsm error for building .NET 4.0 using Microsoft.Bcl.Async

RegAsm error to build .NET 4.0 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 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 is the packages.config project:

 <?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 binds System.Threading.Tasks.dll Version: 2.6.6.0, which is part of this NuGet package. There is no other System.Threading.Tasks.dll target system (Win7 with .NET 4.0 but without .NET 4.5), neither in the GAC, nor elsewhere.

Here is MyAssembly.dll.config , it has the 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 is: does not use RegAsm MyAssembly.dll.config ? How to make it work so that it allows bindingRedirect instructions?

+4
source share
1 answer

The solution I came across is a hack:

  • copied RegAsm.exe and RegAsm.exe.config from C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe to the local folder where MyAssembly.dll :

  • 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> 
  • working now RegAsm.exe /codebase MyAssembly.dll working fine, as expected.

Interestingly, useLegacyV2RuntimeActivationPolicy="true" already exists in the RegAsm.exe.config standard, but that just didn't help.

I think this is the same error 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 .

+4
source

Source: https://habr.com/ru/post/958615/


All Articles