Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference mismatch to System.Threading.Tasks.Extensions #1488

Closed
mtissington opened this issue Mar 28, 2020 · 28 comments
Closed

Reference mismatch to System.Threading.Tasks.Extensions #1488

mtissington opened this issue Mar 28, 2020 · 28 comments
Labels

Comments

@mtissington
Copy link

Using 4.7.2

Not sure when this started but now we are getting the following and can no longer import any file.

`System.IO.FileLoadException: Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

File name: 'System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' ---> System.IO.FileLoadException: Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

File name: 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

WRN: Assembly binding logging is turned OFF.

To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.

Note: There is some performance penalty associated with assembly bind failure logging.

To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

at CsvHelper.Configuration.CsvConfiguration..ctor(CultureInfo cultureInfo)`

@mtissington
Copy link
Author

Resolved - seems to have a dependency on nuget Microsoft System.Threading.Tasks.Extensions

@JoshClose
Copy link
Owner

NuGet should add that for you. What version of CsvHelper?

@mtissington
Copy link
Author

That's what I thought - I'm using the latest version of CsvHelper and needed to add the Extensions manually.

@JoshClose
Copy link
Owner

That's included for the 4.7 build. Maybe it's a fluke?

<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.2" />

@mtissington
Copy link
Author

mtissington commented Mar 28, 2020 via email

@donovan-ecargo
Copy link

donovan-ecargo commented Apr 23, 2020

I'm experiencing the same issue.

Last working version is 13.0.0 for me, with 4.7.2 .net as the framework. It is also the last one without the dependency on System.Threading.Tasks.Extensions.

My guess is that it's something going wrong with the dependency definition for the package

@paulnokes
Copy link

paulnokes commented Jul 22, 2020

I had the same issue running CsvHelper 15.0.5, it seemed to be an incompatibility with System.Text.Json 4.7.2 (may have been 4.7.1). I had to downgrade System.Text.Json to 4.6.0.

@chucklu
Copy link

chucklu commented Nov 5, 2020

I had the same issue but not using CsvHelper, I believed it can be fixed by the same solution. ProjectA referenced a custom libraryB.
I just checked the version of System.Threading.Tasks.Extensions under bin folder, find it's with the wrong verison 4.2.0.0.
Then I tried to scan the dependencies of my bin folder, check which *.exe or *.dll depend on System.Threading.Tasks.Extensions, and print the library and the version of System.Threading.Tasks.Extensions
1
Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51

2
System.Text.Json, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51

The above two libraries was used by libraryB, and when I check the nuget libraries list, I find libraryB depends on System.Threading.Tasks.Extensions with nuget version 4.5.4, which assembly version is 4.2.0.1

My solution is manually add System.Threading.Tasks.Extensions nuget reference with nuget version 4.5.4 in ProjectA directly.

@chucklu
Copy link

chucklu commented Nov 5, 2020

And you will encounter another similar issue, which report the wrong version for "System.Runtime.CompilerServices.Unsafe", it's required 4.0.6.0 version, which mapped to nuget version 4.7.0.
The solution is manually add System.Runtime.CompilerServices.Unsafe nuget reference with nuget version 4.7.0 in ProjectA directly.
https://stackoverflow.com/a/62770487/13338936
1
Microsoft.Extensions.Primitives, Version=3.1.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

2
System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

3
System.Text.Json, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

4
System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

@chucklu
Copy link

chucklu commented Nov 5, 2020

In conclusion, add the following two packages in Project directly(the project which reported the mismatch problem)

     <package id="System.Runtime.CompilerServices.Unsafe" version="4.7.0" targetFramework="net472" />
     <package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />

And the nuget should add the following bindingRedirect for you automatically in config file

   <dependentAssembly>
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
      </dependentAssembly>
 <dependentAssembly>
       <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
       <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
      </dependentAssembly>

@JoshClose
Copy link
Owner

There is another issue for this. Does this help? #1462

@chrishildebran
Copy link

@JoshClose, last week I had success employing a solution @MikeYeager suggested in issue #1462 (Closed), but today I'm yet again bit by this reference roundy-round. I've tried three times to replicate his solution with CSV v16, but it just keeps failing. I've tried to make heads or tails of what the answer is, specifically @chucklu's, but I'm just spinning. Is there a bottom-line solution to this that will allow me to release with confidence?

@chucklu
Copy link

chucklu commented Nov 18, 2020

@chrishildebran Where did you encounter this issue?
1.on developed environment(local machine)? You can provide me a repository which can reproduce it.
2.on deploy environment(test, staging, production)?
3.And what's the exact error info you got?
By the way, I did not have experience about Azure.

@chrishildebran
Copy link

@chucklu, im seeing this error during debuggin in Visual Studio. Cannot provide code. See attached collage of screenshots.
CSV Helper Issue

@chrishildebran
Copy link

I will say that reverting to a previously release's package config (CSV Helper 15.0.5, Microsoft.BCL.AsyncInterfaces 1.1.0, and System.Threading.Task.Extensions 4.5.2 is working. It would be nice to be able to upgrade without worrying though.

@chucklu
Copy link

chucklu commented Nov 19, 2020

@chrishildebran Please configure your visual studio, Tools-->Options-->Projects and Solutions-->Build And Run
Then set the output verbosity to detailed, rebuild your solution, then copy the ouput log and save it as a file, and upload it here.

If it's possible, could you zip your bin folder with the dll files and upload it here, I would like to analysis the dependency of all dll files.

@chucklu
Copy link

chucklu commented Nov 19, 2020

im seeing this error during debuggin in Visual Studio

Did you mean when you run the application directly, there is no problem? Then I guess it should be the problem of visual studio

@chucklu
Copy link

chucklu commented Nov 19, 2020

@JoshClose I find another version mismatch issue NuGet/Home#10302, and it might be bug of nuget.
If nuget does not support auto detection feature, then we need to manually fix these issues.

@JoshClose
Copy link
Owner

I changed all the references to exact version match. Between that and redirects, I think we should be good.

@JoshClose
Copy link
Owner

In 27.2.1 I changed all the references to be >= the lowest version that CsvHelper needs. I changed the test project to use the latest version of every dependency and everything seems to work fine.

@durga-pasupuleti
Copy link

With target framework 4.7.2 the latest Stable Version of CSVHelper still lookin for the Microsoft.Bcl.AsyncInterfaces verison 1.0.0.0. Even though the project contains Microsoft.Bcl.AsyncInterfaces 5.0.0.
Is There any alternative that CSVHelper should load 5.0.0 version as depenceny,

@chucklu
Copy link

chucklu commented Nov 2, 2023

@dplabsindia Do you have the bindingRedirect configuration in your app.config or web.config?

<runtime>
	<assemblyBinding
		xmlns="urn:schemas-microsoft-com:asm.v1">
		<dependentAssembly>
			<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
			<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
		</dependentAssembly>
	</assemblyBinding>
</runtime>

@durga-pasupuleti
Copy link

@dplabsindia Do you have the bindingRedirect configuration in your app.config or web.config?

<runtime>
	<assemblyBinding
		xmlns="urn:schemas-microsoft-com:asm.v1">
		<dependentAssembly>
			<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
			<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
		</dependentAssembly>
	</assemblyBinding>
</runtime>

We have this in web.config. But still the problem persists. CSVhelper looking for assembly 1.0.0.0 of bcl asyncinteraces.

@chucklu
Copy link

chucklu commented Nov 2, 2023

@dplabsindia It should not looking for assembly 1.0.0.0 of bcl asyncinteraces if you have the bindingRedirect in correct config file.
I am just wondering that you did not put the bindingRedirect at the correct place, might in a wrong config file, which you think it's correct one.

Please troubleshooting why your project try to locate assembly 1.0.0.0 of bcl asyncinteraces by using Fuslogvw.exe
View details about a specific failure according this, you should get the detail about why the bindingRedirect does not work for you. From my experience, most time you just configure the wrong file

https://github.com/awaescher/Fusion this tool is better than Microsoft provided Fuslogvw.exe

@chucklu
Copy link

chucklu commented Nov 6, 2023

@dplabsindia Any feedback about the bindingRedirect issue? Have you located the root cause with tool Fusion++ written by awaescher?

@durga-pasupuleti
Copy link

durga-pasupuleti commented Nov 7, 2023

@dplabsindia Any feedback about the bindingRedirect issue? Have you located the root cause with tool Fusion++ written by awaescher?

Not able to use this tool. But I am sure, we have multiple app.config files and one web.config file. The reference is everywhere when we install the package. I can see the bindingRedirect in every .config file. Still, the csvhelper complaining and looking for the 1.0.0.0 version.
Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXXXX' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)\nFile name: 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXXXXX'\n

@chucklu
Copy link

chucklu commented Nov 8, 2023

@dplabsindia why can't you use Fusion++ tool? do you work on windows? maybe you can try the tool Fuslogvw.exe provided by Microsoft

@durga-pasupuleti
Copy link

durga-pasupuleti commented Nov 9, 2023

@dplabsindia why can't you use Fusion++ tool? do you work on windows? maybe you can try the tool Fuslogvw.exe provided by Microsoft

The tool expects SDK on the server. And several other permission issues for now. Meanwhile, I have gone through the
<!-- .NET 4.7 --> <ItemGroup Condition="'$(TargetFramework)' == 'net47'"> <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.0" /> <PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.0" /> <PackageReference Include="Microsoft.CSharp" Version="4.5.0" /> <PackageReference Include="System.Buffers" Version="4.5.1" /> <PackageReference Include="System.Memory" Version="4.5.4" /> <PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.2" /> </ItemGroup>

in thread, #1597 (comment) .

Assuming that by default the 4.7.2 target framework is looking for the 1.0.0.0 which is the runtime error as it is not able to find this version.

All config files as the binding redirect,

<dependentAssembly> <assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" /> </dependentAssembly>

Not sure of these but somewhere the redirect binding failed due to something.

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants