Error: You must add a reference to assembly 'System.Runtime'

Hi to everyone!

NOTE: I am using Experimental .NET 4.6 support!

Using NuGet I’ve added reference to the Humanizer library which follows PCL 259 format.
The problem is that when Unity tries to compile scripts it throws exception:

"Assets/Scripts/ ../MyScript.cs(26,101):
error CS0012: The type `System.IEquatable`1<Humanizer.Bytes.ByteSize>' is defined
in an assembly that is not referenced. Consider adding a reference to assembly
`System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'"

It means that Humanizer library requires System.Runtime.dll library reference in project.

I know, it is quite easy to add reference in the Visual Studio or Rider (I’ve tested: btw, it doesn’t fix the problem — Unity still doesn’t see that changes: obviously, Unity has own lists of assembly references different than presented in the Assebly-CSharp-*.csproj files) but is it possible to teach Unity to add it automatically? This question is important for me also because of *.csproj and *.sln files are excluded from the git repository, so changes about reference imports is not persisted during pushes and pulls. Also, these changes will not handled in Unity Cloud Build.

Is there any generic solution for such kind errors? Is there some place in Unity3d configuration where I am able to control references to the compile assemblies?

P.S. Same error happend with someone and described in the github thread (issue is not related to the Unity3d at all).

Thank you all for any help!
Unity3d — the best :slight_smile:

Hi Meiblorn,

I’m running into a similar issue, but with a different library (Redux.net)

I’ve made only minor progress more than you, sadly it hasn’t been enough to resolve the situation, but maybe if someone from Unity sees this they can weigh in.

You can add a file called “mcs.rsp” to your Assets folder.

In that file, you can add an assembly reference like this:

-r:/path/to/System.Runtime.dll

(I also tried -r:/path/to/System.Runtime without adding .dll)

After adding that line, I stopped getting the error you quoted above. However, that introduced other issues, so I’m still lost.

If you figure it out or anyone can add info, please share!