Unable to use System.Numerics in Unity 2017

I’m trying to use System.Numerics - this was added in C#4 so theoretically now available in Unity 2017 with the 4.6 support. It’s turning out to be stupidly difficult to actually make this work.

In order for the Unity Editor to compile a mcs.rsp file in the Assets folder is required, contents:

-r:System.Numerics

Then reimporting the script or reopening the project will find System.Numerics.

Opening up VS will show code errors however until you manually add a reference to System.Numerics. But … if you try to build / attach to Unity from VS Unity will remove the reference and the build will fail in VS.

Does anyone have a solution for stopping this happening? Or a simpler solution to getting both Unity and VS to be able to build a project including System.Numerics?

Of course the solution is, like with any external assembly, to physically copy the assembly into your project. You should find it somewhere around here:

C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\lib\mono\4.5\

You can’t simply “add a reference” to an external assembly. Everything that your application is using has to be part of the application. Unlike actual managed applications written for the .NET framework, Unity doesn’t require the user to have .NET / Mono installed.

On the chance you’re developing a UWP app, be sure your build platform is set to UWP.