Could not load file or assembly 'System.Collections.Immutable' but i don't have any references to it

Viewed 4272

I'm on V16.4.1 and the project is targeting .NET Framework 4.7.1

I have a solution with multiple projects which all run fine except one which gives the above error. I searched the project and can't find any using references to it and just in case, I added the dll to my references. I searched the entire solution in case I was referencing it through another project but there is no reference to it anywhere

I tried deleting bin & obj folders. Cleaned and rebuilt the project but I get the same error every time.

Edit: The project can build, this only happens when I try to debug it

bin\roslyn\csc.exe is throwing the exception

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.

1 Answers

I use

Visual Studio Professional 2019 ver 16.7.6 / Preview: 16.8.0 Preview 4

and I found the same problem with many 'old' project using .net framework when I compile them from scratch (i.e. deleting bin/obj directories).

The compiler does not recognize that the runtime needs this package, and the solution is to copy in the bin directory the requested version (1.2.3.0 in this case) of DLL System.Collections.Immutable.dll

You can download it adding this line to packages.config file:

<package id="System.Collections.Immutable" version="1.2.3.0" targetFramework="net471" />

but still need to manually copy the .dll in bin directory.

Or add the package with Nuget.

Related