'DotNet Core App 2.1 - Can't add DLL reference

I have a DotNetCore 2.1 Web App (just created it today from the VS 2017 scaffold). This solution also includes a DotNet Core 2.1 Library DLL project. The solution builds ok.

I have another (brand new) DotNetCore 2.1 Web App that wants to use the Library DLL. But when I try to add a new reference (on the Browse tab), it complains:

One or more errors occurred.
The reference is invalid or unsupported.

Any suggestions?

(Curiously, the DLL doesn't show up directly under the Bin\Debug folder like it does in classic .Net; It's under Bin\Debug\netcoreapp2.1)



Solution 1:[1]

I got this error after I moved some of my code repos around and suddenly my .NET Core 2.1 console app wouldn't recognize a .NET 4.5 DLL anymore when I added it.

Turned out that although the broken reference did not show in the solution explorer, the project file still contained it, along with the now broken HintPath to the DLL's old location. Manually removing this reference from the project file solved it.

Solution 2:[2]

Go into your .csproj and make sure the <Reference Include=... is pointing to the correct directory.

For example, my references were pointing to the bin\Debug path of another project when the only build that was actually there was the bin\Release

Solution 3:[3]

In my case, I had a reference to duplicated .dll files. After removing duplication and changing references to different folders got the error above. Cleaning obj, bin and removing the .vs folder from the root directory helped

Solution 4:[4]

I am converting lots of projects to .net6, and one of the projects suddenly refused to let me add .dll files. The solution was to remove the old references first, then add the new references. (The project had references to old .dll files with the same name as the new converted ones.)

Normally Visual Studio lets me add two dlls with the same name but different path, so I later can erase the old one, but in this particular case this did not work. A screenshot and Paint to the rescue for my memory!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Simmetric
Solution 2 Aaron Jordan
Solution 3 Krzysztof Abram
Solution 4 Tornseglare