NuGet Package Management problem - The located assembly's manifest definition does not match the assembly reference

Viewed 286

I've got bunch of .NET Framework 4.8 projects within a Visual Studio solution. I manage nugets on the solution level to ensure all projects use same versions of nugets. I have made sure there are no multiple versions installed of any one nuget.

The solution contains libraries which are extensions to another proprietary application for which I have no source code for. Think Interner-browser extensions. The solution includes a dummy console application which references the libraries to ensure dependency management is handled properly.

I've got several projects that depend on CsvHelper. CsvHelper in turn depends on Microsoft.Bcl.AsynInterfaces >= 1.0.0. The projects all use Microsoft.Bcl.AsynInterfaces 6.0.0.

Binding redirect is in place for Microsoft.Bcl.AsyncInterfaces.

<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />

Following entry can be found in the build log.

Unified primary reference "Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51". (TaskId:20) Using this version instead of original version "1.0.0.0" in "E:\Visual Studio...\packages\CsvHelper.27.2.1\lib\net47\CsvHelper.dll" because AutoUnify is 'true'. (TaskId:20)

Whenever a project attempts to use CsvHelper at runtime, I get following error.

Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.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) at <Method which uses CsvHelper>

This exact same problem repeats with two other nugets.

The second being ExcelMapper, which depends on System.Text.Json >= 6.0.0. If I upgrade from 6.0.0 to 6.0.1, I get identical error as with CsvHelper and Microsoft.Bcl.AsyncInterfaces.

The third one is NPOI, which depends on SharpZipLib >= 1.3.2. If I upgrade from 1.3.2 to 1.3.3, the same problem occurs.

In both cases proper bindingRedirect is set up automatically.

I have other nugets such as MySql.Data which depends on BouncyCastle >= 1.8.3.1 and I am using 1.8.9. MySql.Data also depends on Google.Protobuf >= 3.6.1 and I am using 3.19.3.

Why is nuget dependency management working on some, but not all nugets?

What I have tried so far:

  • Clean solution in Visual Studio
  • Emptying Release and Debug folders under bin and obj.
  • Clearing all caches with dotnet nuget locals all --clear and mage.exe -cc
  • Reinstalled all nugets with update-package -reinstall
  • FusionLog only tells me a file is missing and does not specify anything further.
  • Removed all binding redirects and disabled auto-generation of binding redirects. (Restored them back later)
  • Tried Visual Studio 2019 and 2022
1 Answers

It was suggested elsewhere that I add bindingRedirects to the host application's app.config-file. This solved these issues I had.

New problem is that I don't know how to update the host application's app.config as part of the build process, because the host app is not part of the solution, since it's proprietary. Perhaps I'll ask a new question regarding this if I can't find a solution on my own.

Related