Unity and MathNET


I am having a very noob(ish) problem. I would like to use the MathNet.Numerics Library. When I add the following to my code (only that line to code that works otherwise) and add MathNet.Numerics.dll to my references in MonoDeveloper I can build the file. However when I go to run (push the play button) my unity project I get the following error.

using MathNet.Numerics.IntegralTransforms;

error CS0246: The type or namespace name MathNet could not be found. Are you missing a using directive or an assembly reference?

I have the MathNet.Numerics.dll file in the same folder as UnityEngine.dll.

I’ve tried putting the MathNet.Numerics.dll file into my project folder (Assets) but that give the following error.

TypeLoadException: Could not load type ‘MathNet.Numerics.Algorithms.LinearAlgebra.ILinearAlgebraProvider’ from assembly ‘MathNet.Numerics, Version=, Culture=neutral, PublicKeyToken=null’.

I don’t understand what the problem is. Please Help.

I got this working.


  1. Create a folder called Assets/Plugins in your project.

  2. go to
    https://onedrive.live.com/?id=84F3672F8CDA3E91%21440210&cid=84F3672F8CDA3E91 (link is dead)
    and download the latest version of MatNet.Numerics.dll in zip format.

  3. open the folder called Net35. Unity apparently only runs on this version of .net.

  4. copy BOTH MathNet.Numerics.dll AND System.Threading.dll into Assets/Plugins/.

Note: Don’t touch anything in MonoDevelop. it should reference it automatically.

For me i was installing the newer .net version and I didn’t realize it also needed System.Threading.dll. Once I got it in the above format it worked fine.

FYI: I’m on El Capitan OSX11.4 and Unity-5-3.4f1 personal.

Hope that helps!

You don’t add the reference in monodevelop, you add the .dll to your unity project in the editor, which should then add it for use via the “using” statement.
Here is the documentation for it:


Well, this answer helped find the answer.
I was able to get the Math.NET Numerics 3.9 running on unity on osx El Capitan.

Here are the steps I took:

  • Install NuGet in Monodevelop using this tutorial Xamarin Studio with NuGet - YouTube
  • Search for and install Math.NET Numerics using the NuGet plugin. That will also install System.Threading for which you’ll have to accept a license agreement.
  • Close monodevelop.
  • NuGet creates a directory called packages under the project folder.
  • I copied “packages/TaskParallelLibrary.1.0.2856.0/lib/Net35” to a folder I named Assets/Libs.
  • Then I also copied the contents of “packages/MathNet.Numerics.3.9.0/lib/net35” to “Assets/Libs/Net35”.
  • For correctness sake I placed the readmes and licenses under “Assets/Libs”.
  • Finally I deleted the packages directory, and the file Assets/packages.config

That’s it. You can test it by dragging the following script onto an object:

using UnityEngine;
using System.Collections;
using Matrix = MathNet.Numerics.LinearAlgebra.Matrix<double>;
using Vector = MathNet.Numerics.LinearAlgebra.Vector<double>;

public class MathTest : MonoBehaviour {
	// *************************************************************************
	void Start() {
		Matrix A = Matrix.Build.DenseOfArray(new double[,] {

		Vector b = Vector.Build.Dense(new double[] {1, 1, 1});

		Vector x = A.Solve(b);
		Debug.Log("x = A^-1b: " + x);

MathNet requires .NET 4, which unity’s version of monodevelop doesn’t support.

If you manage to get it working, please tell me! I’ve been trying to use Iridium’s stable distribution, but it’s giving me bogus numbers. Iridium was discontinued in 2008 so I’m thinking it has lots of bugs. And I really don’t want to implement my own probability distributions.

You could use Math.NET for Unity Unity Asset Store - The Best Assets for Game Making
Unity Asset Store - The Best Assets for Game Making

In case people are still struggling with this in 2023.

Download NuGet package manager for unity:

And follow these steps:

  1. add the NugetForUnity.unitypackage to your Unity Project.
  2. Open the NuGet > Manage NuGet Packages Window
  3. Search the MathNet.Numerics and install

(Original Answer from SharkWithLazers probability - How to make MathNet.Numerics work with Unity? - Game Development Stack Exchange)