This project has moved and is read-only. For the latest updates, please go here.

Is MathNet.Numerics depends on System.Threading.dll?

Jul 2, 2014 at 7:46 PM
Edited Jul 2, 2014 at 7:49 PM
I am using polynomial regression method from MathNet, and I got error message as follwing

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'MathNet.Numerics.LinearAlgebra.Matrix1' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MathNet.Numerics.LinearAlgebra.BuilderInstance1' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Threading, Version=1.0.2856.102, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Threading, Version=1.0.2856.102, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at MathNet.Numerics.LinearAlgebra.BuilderInstance`1..cctor()

=== Pre-bind state information ===
LOG: User = BROOKHAVEN\lzhao
LOG: DisplayName = System.Threading, Version=1.0.2856.102, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/Bicw_Dev/Bicw32/ParticleSolutions/
LOG: Initial PrivatePath = NULL

Calling assembly : MathNet.Numerics, Version=3.0.2.0, Culture=neutral, PublicKeyToken=null.

LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Bicw_Dev\Bicw32\ParticleSolutions\uRheApp.exe.Config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: System.Threading, Version=1.0.2856.102, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Bicw_Dev/Bicw32/ParticleSolutions/System.Threading.DLL.
LOG: Attempting download of new URL file:///C:/Bicw_Dev/Bicw32/ParticleSolutions/System.Threading/System.Threading.DLL.
LOG: Attempting download of new URL file:///C:/Bicw_Dev/Bicw32/ParticleSolutions/System.Threading.EXE.
LOG: Attempting download of new URL file:///C:/Bicw_Dev/Bicw32/ParticleSolutions/System.Threading/System.Threading.EXE.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I have no idea what cause this problem. Could anyone help? Thanks!
Jul 2, 2014 at 8:03 PM
Edited Jul 2, 2014 at 8:03 PM
Are you targeting .Net 3.5? Only the .Net 3.5 version is supposed to depend on that assembly of the TaskParallelLibrary NuGet package.

We should make this explicit in the NuGet package with a platform-dependent dependency if possible, so the TaskParallelLibrary is added automatically if, and only if, the project is targeting .Net 3.5.

Thanks,
Christoph
Marked as answer by wltz on 7/2/2014 at 12:53 PM
Jul 2, 2014 at 8:52 PM
Hi, Christoph

Yes. The target framework is .Net 3.5.
After I add the reference Task Parallel Library for .Net 3.5, problem solved. Thanks a lot!!!

One more question :)
Before I add MathNet.Numerics into my project. I tested it in a simple project, just to test polynomial regression function, and it works fine. I am just curious, what could cause to throw the exception that could not load the assembly System.Threading ?

Thanks!

Liang
Jul 2, 2014 at 9:32 PM
Was the simple test project by chance targeting .Net 4?

Polynomial regression is currently implemented with linear algebra routines, some of which are parallelized and thus cause the threading infrastructure to be loaded, if not loaded yet. On .Net 4 and higher we do parallelization using the .Net base class libraries directly, but on .Net 3.5 we have to use that package which ports some of the missing tools back to .Net 3.5.

Thanks,
Christoph
Marked as answer by wltz on 7/2/2014 at 1:53 PM
Jul 2, 2014 at 9:52 PM
Again, you are right. The testing project targeting .Net 4.
Seems TPL is required if target framework is .Net 3.5.

Thanks for the answer!

Best Regards,
Liang