6

If you try to add a NetStandard library dll to a .net core application Visual Studio throws the error:

instance object was created as immutable

And refuses to add the reference.

Tod
  • 2,070
  • 21
  • 27
  • Hi Tod, glad to know you've found the solution to resolve this issue! Please consider accepting it as an answer to change its status to Answered. It will also help others to solve a similar issue. See [can I answer my own question..](https://stackoverflow.com/help/self-answer), Just a reminder :) – Jiale Xue - MSFT Jul 12 '22 at 08:30

2 Answers2

13

I thought I would share this as nothing much turns up in a search. You need to add a reference to the NetStandard.Library NuGet Package, before you can add a .netstandard library.

https://www.nuget.org/packages/NETStandard.Library

Then add references to the DLL.

As a side note, I never had any issues adding a project reference to a netstandard 2.0 project, but to its output dll - I did.

Tod
  • 2,070
  • 21
  • 27
  • 1
    It was a few hours of head scratching, that's to be sure. With several emails bothering a 3rd Party dev for "the right dll" I realised it was just affecting net standard 2.0 DLLs. Then a shot in the dark found the Nuget package. – Tod Jul 25 '22 at 15:03
4

I had this issue when trying to add a reference to the TwinCat.ADS library. My issue turned out to be the opposite of yours. I had added the package using NuGet. NuGet didn't install the package correctly but was preventing me from adding the reference to the dependencies separately. I had to remove the package from NuGet before I could add the library to the references.