5

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.

Community
  • 1
  • 1
NoIdeaHowToFixThis
  • 4,484
  • 2
  • 34
  • 69

3 Answers3

6

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.

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
  • Hi, thanks for the hint, but `#I` did not work either. However, after trying your suggestions, I switched back to the old code and this time the thing works. I checked with the version control and the code is exactly as it was before. I do not understand what went wrong in first place. – NoIdeaHowToFixThis Dec 03 '13 at 09:51
  • btw, I'd be happy to read a tutorial , if you know any, about how to troubleshoot this issues with referencing. – NoIdeaHowToFixThis Dec 03 '13 at 09:59
  • Also, F# Interactive occasionally gets confused when you reference different versions of assemblies - the easiest fix is to restart F# interactive (right click - restart) – Tomas Petricek Dec 03 '13 at 11:29
  • Ok, thank you all. I'll keep the suggestions in mind. As I am new to F#, I found referencing a tricky thing. – NoIdeaHowToFixThis Dec 03 '13 at 14:53
  • 1
    I've just had the same problem and the #I fixed it! – pierroz Feb 02 '15 at 15:55
5

This is still a problem. I can also reproduce and fix the problem as follows:

I have three projects:

  1. Informedica.Settings.Library
  2. Informedica.Settings.Services.Interfaces
  3. Informedica.Settings.Services.Models

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.

halcwb
  • 1,480
  • 1
  • 13
  • 26
  • 1
    Wow, I never thought that the order with which you reference the dlls mattered! Thanks for pointing this out! This is still a problem in VS 2015 with the latest f# release (V4.0.Update2.Preview-12.18.2015). – Lars May 02 '16 at 11:36
2

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.

John Palmer
  • 25,356
  • 3
  • 48
  • 67
  • As per the post, everything has been referenced 1) in the solution explorer, for both projects 2) via `#r` and finally opened with `open` – NoIdeaHowToFixThis Dec 03 '13 at 09:08
  • Okay, so the error message is saying that this specific thing has not been referenced. Also, `open` is irrelevant here – John Palmer Dec 03 '13 at 09:08
  • I have no idea where the problem could be. I have removed the reference and added it back with nuget, then done the same with the package manager console; I have also tried to shuffle the order of the #r dependencies but no luck. – NoIdeaHowToFixThis Dec 03 '13 at 09:15
  • I am working on a toy project, where I have trimmed all the rest and left only the piece of code that generates the issue. Thanks. – NoIdeaHowToFixThis Dec 03 '13 at 09:22