I have a .NET Standard 2.0 DLL project.
It has no other references, apart from NETStandard.Library 2.0.1
and all is fine.
It is referenced by a WPF application and everything seems to work fine.
Once I add a nuget package for System.Collections.Immutable 1.5.0
to the DLL project, a yellow exclamation mark appears on the Dependencies
root of the Solution Explorer. (Hm... I now see that the exclamation remains even after I remove this package, but I guess this is a VS bug since everything seemed to work just fine before adding this library)
Having both packages, everything builds fine, but when I try to use the ImmutableDictionary
, I get this:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
Looking at the nuget packages, I understand that those two should work together, since (from my understanding) the 'System.Collections.Immutable` library says it supports .NET standard 2.0.
I am very new to the .NET Standard world.
Looking at the public key token of the System.Collections.Immutable.dll
in my main app's bin
folder I see that it was indeed b03f5f7f11d50a3a
as expected. However the version is different.
Normally, in the old .NET I would try to add an assembly redirection in the app's config file. But doing this here does not seem to make any difference. Adding this into my WPF app that references the DLL:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
... changes the exception to this:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Collections.Immutable, Version=4.0.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
Inner Exception
FileNotFoundException: Could not load file or assembly 'System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
What is going on here? Can't I use those two nuget packages together?
UPDATE:
I now notice that the DLL version that I got was from System.Collections.Concurrent.dll
, while I am interested at System.Collections.Immutable.dll
which is nowhere to be found on my bin folders...
I haven't even found where the nuget packages are stored in my solution.
UPDATE 2:
It turns out that I get the exact same behavior when I create a new solution with similar setup (Full framework console app referencing .NET Standard 2 DLL).
Following @Lasse Vågsæther Karlsen's advice, I have downloaded the nuget package from here https://www.nuget.org/packages/System.Collections.Immutable, extracted the correct DLL out of it, and placed it in my bin folder. Then the console app worked.
I am using the 15.7.1 version of Visual Studio. I am not sure what are the changes are of this being fixed in the latest 15.7.2 version...
You can try my verifiable example by downloading it from here: https://mega.nz/#!YZMwGABD!eHHxvNdO59l2m5ZlHMG1vvqCd-GHv3EVckR-9htDojs
Broad platform support. . NET Standard 2.0 is supported on the following platforms: . NET Framework 4.6.
You cannot consume a . Net Standard 2.1 assembly in any . Net Framework Version because the . NET Framework (even the last ever version, 4.8) does not implement .
NET Standard 1.3 will be compatible with apps that target . NET Framework 4.6, . NET Core 1.0, Universal Windows Platform 10.0, and any other platform that supports .
NET 5 and all future versions will always support . NET Standard 2.1 and earlier. The only reason to retarget from . NET Standard to .
There are 2 ways to fix this:
1 - Update the project file for the ConsoleApp1 to include this in the property group
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
2 - Add a reference to System.Collections.Immutable
directly in the ConsoleApp1
project.
This is a known issue where using Project-to-Project references and NuGet package references does not automatically flow the references correctly. This is being tracked here but one of these workarounds should unblock this.
For my case, it turn out to be projects in the same solution have different versions of System.Collections.Immutable.dll. (1.4.0 and 1.5.0)
Some how MSBuild does not notice that there are 2 versions of the dll and trying to find and load dll version 1.5.0 instead of 1.4.0 in some project.
To solve this just update and make sure that every proj. in the same sln has the same version of the dll.
I face this problem with System.Net.Http also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With