I am aware that there are already other questions on the topic, such as:
.. but hey, I am new to F# and still don't get it.
I have a F# project (thelibrary
) which contains some modules. This project references in the solution explorer all the necessary libraries. Each .fs
file opens the libraries used in the module. The F# project compiles properly.
I have then another F# project which contains a script. I reference thelibrary
and the libraries used by thelibrary
itself. In the script I reference with #r
the dll with thelibrary
and all the libraries used by thelibrary
. I then open
all the modules.
Intellisense says all is allright until I execute the script.
The script returns the error:
error FS0074: The type referenced through 'Fmat.Numerics.Matrix`2' is defined in an assembly that is not referenced. You must add a reference to assembly 'Fmat.Numerics'.
What is the procedure to hack this problem? How do I proceed from there? I am interested is a solution to this specific problem but, as well, a cookbook recipe to fix this type of issues that have been quite a source of frustration for me.
Thank you.
The behavior of F# Interactive can be a bit odd in this case. In general, I think that things work better when you use #I
to include the path with referenced assemblies in the resolution context and then reference the libraries by name using #r
. So if you have a library Fmat.Numerics.dll
in a folder C:\libs
and it references another library another.dll
then you can do:
#I "C:\\libs"
#r "another.dll"
#r "Fmat.Numerics.dll`
The first line means that F# Interactive will automatically look in the folder with your libraries (this can be relative path to your script location too) - as a result, the next two lines can just reference the libraries by their file names.
This is still a problem. I can also reproduce and fix the problem as follows:
I have three projects:
Project 2 uses project 1 and project 3. Project 1 uses project 3.
When I load the references in the order (first proj 3 then proj 1):
#r @"..\..\Informedica.Settings.Services.Models\bin\Release\Informedica.Settings.Services.Models.dll"
#r @"..\..\Informedica.Settings.Library\bin\Release\Informedica.Settings.Library.dll"
Everything works. Unfortunately, when I use the VS2013 send references to fsi or use the new power tools generate references option, the order is:
#r @"..\..\Informedica.Settings.Library\bin\Release\Informedica.Settings.Library.dll"
#r @"..\..\Informedica.Settings.Services.Models\bin\Release\Informedica.Settings.Services.Models.dll"
This will result in the FS0074 error. Apparently, because a type from Services.Models is used in Settings.Library and the order of reference is reversed, fsi cannot handle this. Correcting the order of referencing solves the problem.
Running things in fsi does not add references from the project, you need to use #r ...
. The error message is reasonably obvious in what you need to do - add a reference to Fmat.Numerics
. It is also possible that you have such a reference, but that fsi is sensitive to the load order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With