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

3

11

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.

Partible answered 19/3, 2020 at 12:48 Comment(7)
Are you referencing any nuget packages?Priestess
Could be that another lib is referencing it, what libs are you depending on?Stealer
@MattEvans no, local dlls onlyPartible
i.e Third party dlls? Check them out with reflector, see what they reference.Priestess
Hmm - looks like reflector is paid now. Dotpeek is free : jetbrains.com/decompilerPriestess
@MattEvans I'll wait for the next VS Update maybe as the project runs fine, it's only when I try to debug that it's an issuePartible
It is the compiler that keels over, not your project. On my machine, v1.2.3.0 of System.Collections.Immutable.dll is located in the C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin directory. YMMV, not a good kind of problem to have. Check disk health, spin the repair/reinstall wheel of fortune.Dillie
G
4

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.

Grieg answered 20/10, 2020 at 8:20 Comment(0)
M
0

Stefano's answer worked for me

this file is a dependency from my firebase dll, tough i didn't need to modify packages.config because the file exists in my bin folder

I just included System.Collections.Immutable.dll file in in VS project

then changed in file properties > advanced > copy output > copy always

thanks!

Mahmoud answered 23/11, 2022 at 8:33 Comment(0)
H
0

i also had this issue :

An exception occurred while invoking executor 'executor://mstestadapter/v2': Could not load file or assembly 'System.Collections.Immutable, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

go on you nuget panel of your solution, and search for this package which might be already installed for some csproj:

nuget installed package

on the right you see the list of csproj who have this package installed, you testing csproj might not be checked . Install it on your testing csproj, rebuild and recheck the output of the csproj.

Hylomorphism answered 27/2 at 15:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.