Using MathNet.Numerics
Author: Panache
Creation Date: 1/12/2017 6:30 PM
profile picture

Panache

#1
I'd like to be able to use a linear algebra library in Wealth-Lab Pro, specifically https://numerics.mathdotnet.com/.

I assume it isn't possible to use NuGet, so I downloaded the zip file. I also assume there isn't a way to use <loadFromRemoteSources> https://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx, so I changed the properties of MathNet.Numerics.dll to unblock it's Security. I then added a reference to the .dll in my Strategy, but when I try to use any of the linear algebra functions, I get a runtime error, "Cannot load file or assembly 'MathNet.Numerics, Version 3.16.0.0 . . . . The system cannot find the file specified."

CODE:
Please log in to see this code.


I am sure what I'm doing is unsupported, but I'd appreciate any ideas as to how to make this or another linear algebra library work in Wealth-Lab Pro.

profile picture

Eugene

#2
It works. You don't even have to add a reference to the DLL. When I...

1. uncheck "Downloaded from the internet" in the file's properties,
2. copy the DLL to the WLD main folder under Program Files, and
3. restart WLD,

...this is what I get after running a PrintDebug on your code:
CODE:
Please log in to see this code.


QUOTE:
DenseMatrix 3x4-Double
1 1 1 1
1 2 3 4
4 3 2 1


Last but not least, I took the assembly from /lib/net40 of mathnet.numerics.3.16.0.nupkg (if that matters).
profile picture

Panache

#3
Thanks. It works. The only two things I did differently were to copy the dll to the program directory and restart Wealth-Lab Pro.
profile picture

Eugene

#4
Glad to help.
profile picture

kmckiou

#5
I know I must be missing something, but I have been trying for hours to get WLP 6.9.20.7 to recognize the MathNet.Numerics.dll file. I was able to add a reference to it in Visual Studio 2017 and use it in a little program, but am unsuccessful with WLP 6.9. BTW, I extracted teh .dll from mathnet.numerics.4.8.1.nupkg.

I added the .dll to the C:\Program Files\Fidelity Investments\Wealth-Lab Pro 6 directory and restarted WLP, but it is not recognized when trying to use it in a strategy. I can add a reference in the strategy ("Other Assemblies to Reference") and that appears to work (it is still there after saving and restarting), but when I try to add a "using" directive or simply use the namespace directly, I get an error that MathNet namespace cannot be found.

I also tried adding a reference to the .dll in another directory, but had the same result.

It seems the only namespaces it will recognize are namespaces.installed with Wealth-Lab.

Also, I am using the same code as Panache.

I'm stumped. Any ideas?

Thanks,
- Kevin
profile picture

Eugene

#6
Kevin,

I think this may happen if post #2 is not followed closely i.e. you haven't unchecked "Downloaded from the internet" in the file's properties. Or I fail to see this step mentioned in your post. At least this was in Windows 7 whereas in Windows 10 it's the other way round - one has to check "Unblock" and OK the dialog.

How to unblock files downloaded from Internet in Windows 10
profile picture

kmckiou

#7
Eugene,

Thanks for the reply. I am not able to download directly to the Fidelity Investments\Wealth-Lab Pro 6\ folder. So, I download it to the Downloads directory, unblock the file, extract the MathNet.Numerics.dll and copy (or cut and paste) to the Fidelity Investments\Wealth-Lab Pro 6\ folder.

I am using Windows 10 and the WLP IDE for development. So, it seems I am stuck.

As I said before, I have no trouble when using Microsoft Visual Studio. Maybe there is a way to develop WL programs using MVS...I have not looked into it.

I really would like to use the WLP IDE since it is nicely integrated. I am also concerned that I will run into the same problem if I develop a .dll in MSV and try to add a reference to it in WLP IDE.

Any ideas are welcome.

Thanks,

- Kevin
profile picture

Eugene

#8
I've double checked that the code in posts #1-2 (and nothing else) runs just fine in 64-bit versions of WL 6.9.15 and 6.9.20 alike, using net40 and net461 builds of the library v4.8.1. And I also made sure that the syntax errors from inadvertent copying of the netstandard build would be different. Haven't tested 32-bit WL though.

So I gather that you may have 2 versions of WLP installed (32-bit and 64-bit) and doing copy/paste to one and starting the other build.

Please run this and attach the TXT files here:

CODE:
Please log in to see this code.


Of course there's a way to develop WL strategies in MS VS but let's get this issue troubleshooted first.
profile picture

kmckiou

#9
Eugene,

Nope. I only have WLP 64 bit installed. I even uninstalled it (also checking for other versions) and re-installed it. I checked the shortcut I use to start it and it is pointing to the WealthLabPro.exe in the Fidelity Investments\Wealth-Lab Pro 6\ folder. I even directly started WLP by double-clicking the .exe file...no difference.

I am downloading mathnet.numerics.4.8.1.nupkg to C:\Users\kmckiou\Downloads\ folder.

I then open the properties and check the "unblock" check-box.

I extract MathNet.Numerics.dll from the Downloads\...lib\net40 folder

and copy it to C:\Programs Files\Fidelity Investments\Wealth-Lab Pro 6\ folder.

I then start WLP 6 and open my "NumericTest" strategy, go to the "Editor" tab and click the "References" menu pop-up. The MathNet.Numerics does not appear in the .Net Framework tab. So, I add it in the "Other Assemblies to Reference" tab. I save it, exit WLP and then restart WLP.

When I again open the NumbericTest strategy, the "using MathNet..." directive has a squiggly line under it and when hovering over it I get the error message indicating the namespace "MathNet" could not be found. See the attached jpg file.
profile picture

kmckiou

#10
Here are jpg images of the .NET Reference and Other Assemblies to Reference pop-ups.

- Kevin
profile picture

kmckiou

#11
Here are images of the MathNet.Numerics.dll General and Security properties pop-up.
profile picture

Eugene

#12
QUOTE:
So, I add it in the "Other Assemblies to Reference" tab. I save it, exit WLP and then restart WLP.

Neither step is required. Once you put the DLL in after starting WLP, the next opened Strategy window will "pick up" the DLL. (You won't be able to delete/overwrite it until WLP is closed, though). And a reference to it is not required at all.

QUOTE:
The MathNet.Numerics does not appear in the .Net Framework tab.

It should not appear there as it's not part of the GAC (.NET global assembly cache). But putting it there may be the workaround for you!

So, give this a try:

How to: Install an assembly into the global assembly cache
How do I register a .NET DLL file in the GAC?

P.S. I notice that you're using JPG for screenshots (and it's suboptimal). Hope this famous comics make you reconsider ;)

JPEG or PNG – Which Image Format Offers Better Quality?
profile picture

kmckiou

#13
Ahhh...It looks like the issue may be the lack of a "strong name". See the attached gacutil screenshot.

I need to get on with some other stuff. So, I will have to come back to this later today or early tomorrow. At least it seems like this may be getting somewhere.

I suspect the issue is the tool I used to unpack the .dll. I just used 7-zip. Maybe there is a better tool for extracting the .dll.

I'm a retired eclipse/Java/Maven/Linux developer...so, this .NET stuff is all new to me.

My experience has always been that setting up the development environment is one of the most difficult and critical steps in any development.

Thanks for your help!

Oh...notice the screenshot is .png ;-)

- Kevin
profile picture

superticker

#14
QUOTE:
I have been trying for hours to get WLP 6.9.20.7 to recognize the MathNet.Numerics.dll file. I was able to add a reference to it in Visual Studio 2017 and use it in a little program, but am unsuccessful with WLP 6.9. BTW, I extracted teh .dll from mathnet.numerics.4.8.1.nupkg.
This is how I use MathNet.Numerics with very good success:

1) nuGet the MathNet package using Visual Studio and have it install it in your WL project development directory. That install step "might" also handle the strong naming issue, but I'm not sure.

2) Move the MathNet.Numerics.dll file to the WL install directory. Unlike your own WL DLL libraries, where you must remain file "owner" so you have full access rights during subsequent VS builds into the WL program directory, the MathNet.Numerics.dll file can be owned by Administrators since you won't be building that yourself with VS.

3) Write/make calls to MathNet from your own private WL User.Components.dll library created by VS so:
3a) you do not need a using statement to MathNet.Numerics from WL's own toy editor. Rather, include the using statement in your own WL User.Components.dll code instead.
3b) so you do not expose MathNet data types (e.g. Matrix, Vector) to WL strategies. That simplifies strategy development.
profile picture

kmckiou

#15
I tried a bunch of things and I always get a squiggly line under the using MathNet.Numerics.LinearAlgebra with a popup message that MathNet namespace cannot be found. Then, if I add it to the additional references and try to run the strategy, I get this message:

error CS1703 @ (0,0): An assembly with the same identity 'MathNet.Numerics, Version=4.8.1.0, Culture=newtral, PublicKeyToken=3cc9227b2466e207' has already been imported. Try removing one of the duplicate references.

So...it does recognize the MathNet.Numerics.dll that is in the install directory or in the GAC - not sure which, but, if I remove the manually added reference and try to run it, I get a new error:

error CS0103 @ (15, 23): The name 'DenseMatrix' does not exist in the current context.

So, I tried something really simple:

CODE:
Please log in to see this code.

It still does complain that MathNet namespace is not found. This must be a bug because it compiles and runs successfully!!! Furthermore, there are no squiggly lines on the line float x = (float) num.Constants.Pi;

So, now, I went back to the original code. It seems there is a bug in the code. DenseMatrix is not a a child of LinearAlgebra. It is a child of LinearAlgebra.Double. So, I modified the code as follows:

CODE:
Please log in to see this code.

Now, it compiles an runs!!!

So, it does seem there is a bug in WLP editor in that it complains that MathNet namespace is not found, even though it clearly is recognizing it.

Thanks,

- Kevin


profile picture

Eugene

#16
QUOTE:
Try removing one of the duplicate references.

That's expected. WL has loaded the assembly from GAC or its main program folder already, no need in the added Reference in the Editor then.

QUOTE:
It still does complain that MathNet namespace is not found. This must be a bug because it compiles and runs successfully!!!

Indeed. This must be an issue of the upgraded Editor in WLP 6.9.20.7. It's too "verbose" in the sense that it puts red squiggles in successfully compiled code. You can simply ignore them when it runs until 6.9.21 fixes it. To find out more on this and its other known issues see this thread: List of WLP 6.9.20.7 Issues and Fixes
profile picture

superticker

#17
CODE:
Please log in to see this code.
I'm not sure what the "la = ..." part is all about (leave that off), but for what you're doing, you need:
CODE:
Please log in to see this code.

You may need other using statements as well depending on what high level functions you're using. Some functions (e.g. signal processing [includes windowing classes] and Kalman filter) are a separate download.

EDITED by Eugene: deleted offtopic that concerns Strategy development using the VS IDE
profile picture

Eugene

#18
All posters please be aware that any general discussion regarding development in Visual Studio IDE should take place in other, more appropriate threads. This topic focuses on the MathNet.Numerics library exclusively.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).