0

I'm using C#, .NET CORE 3.1, Visual Studio 2019.

The source solution contains many projects which using jenkins for build by command:

dotnet publish -f netcoreapp3.1 -r win-x86 --self-contained false /p:AssemblyVersion=\"1.1.1.1\" /p:Version=\"1.1.1.1\" /p:FileVersion=\"1.1.1.1\" -c release MySolutionFile.sln -o sln_build/MyProductBuild/win_x86"

I have to say in past months it works great, until days ago, I pull down a build artifacts and run it, an error was thrown:

Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)

I looked the file Microsoft.Extensions.DependencyInjection.Abstractions.dll in artifacts folder, the File Version was showing 2.2.0.18315, obvious this is a wrong version, the expecting one should be with version 5.0.0.0.

Then I'm trying to locate which project referenced this wrong version:

  • I searched *.csproj and *.deps.json for each projects under the solution, could not see any project referened the wrong version, all referenced to 5.0.0.0.

  • Delete all obj and bin folder under each projects, and then re-publish, still no luck.

Any suggestions?

[edit0]

  • Multiple .NET CORE SDKs installed on this build machine:

.NET SDKs installed: 2.1.811 [C:\Program Files\dotnet\sdk] 2.2.105 [C:\Program Files\dotnet\sdk] 3.0.103 [C:\Program Files\dotnet\sdk] 3.1.100 [C:\Program Files\dotnet\sdk] 3.1.403 [C:\Program Files\dotnet\sdk] 5.0.201 [C:\Program Files\dotnet\sdk]

  • the packages in my build machine is located at:

C:\Windows\System32\config\systemprofile.nuget\packages

I removed the folder: microsoft.extensions.dependencyinjection and microsoft.extensions.dependencyinjection.abstractions.

  • after a new build, can see the above folders were created again and filled with different version of this assembly, include version 2.2 and 5.0 and others.

  • after a new build, the Microsoft.Extensions.DependencyInjection.Abstractions in each project's bin folder is with correct version, that means only the solution output folder get the wrong version.

Shawn
  • 702
  • 1
  • 9
  • 36
  • Please try the following suggestions: 1.Right click on reference -> properties -> change 'Specific Version' to false. 2.Cleaning old versions installed at C:\Users\USERNAME\.nuget\packages\ – DanielZhang-MSFT Sep 06 '21 at 02:53
  • @DanielZhang-MSFT I can't see the `Specific Version` option in my VS(Eneterprise 2019 Version 16.11.2). I cleared the `packages` (as my edit explained) folder but seems no impact. – Shawn Sep 06 '21 at 07:50
  • Right click on the specific reference in the References directory. And please try to put in a binding redirect in your web.config file like this thread:https://stackoverflow.com/questions/4187907/net-picking-wrong-referenced-assembly-version – DanielZhang-MSFT Sep 07 '21 at 05:36
  • the `binding redirect` may a way to fix this(though .NET CORE seems not directly support), I still want to know where exactly this `wrong reference` come from. thanks. – Shawn Sep 07 '21 at 07:46
  • Please check your Global Assembly Cache in %windir%\Microsoft.NET\assembly.https://learn.microsoft.com/en-us/dotnet/framework/app-domains/gac – DanielZhang-MSFT Sep 07 '21 at 08:40

0 Answers0