Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scripts don't recognize FSharp.Data

Somewhat of a F# beginner. I'm trying to test out some of my XmlTypeProvider code in the interactive window by first entering it in a script (fsx) file. The script file won't recognize the following

open FSharp.Data  // gives "The namespace or module 'FSharp' is not defined"

Everything has been added to reference, and .fs files seem to not have any problems finding the XmlTypeProvider reference but for some reason, a script in the same project does not. I even got the code to work in a .fs file.

I added FSharp.Data with nuget and everything seem to add correctly. What am I missing here?

like image 735
user2344035 Avatar asked May 02 '13 17:05

user2344035


2 Answers

Add a reference in the script to the nuget packages folder that contains FSharp.Data.dll. That folder also contains the designer dll (FSharp.Data.DesignTime.dll)

#r @"<your nuget packages folder>\FSharp.Data.2.1.0\lib\net40\FSharp.Data.dll"
like image 141
jdearana Avatar answered Sep 23 '22 19:09

jdearana


Incidentally, I was just debugging this error last week. There are essentially three possible reasons:

  • The file could not be found. The most obvious one is that F# actually cannot find the dll file. Make sure the reference is correct (check References in the project properties) or make sure your #r points to the right file (when using an F# script file)

  • Type provider is not trusted. The type provider is blocked by Visual Studio. This can happen if you click on "Disable" when you load the provider for the first time. To fix this, go to "Tools" - "Options" - "F# Tools" - "Type Providers" and enable the type provider (check "Trusted").

  • The DLL is blocked by OS. Finally, if the dll comes from an untrusted source, Windows might block it (this happens especially if you download a zip file and extract the file using Windows). To unblock the file, go to file properties and click "Unblock". There is a good description here..

like image 25
Tomas Petricek Avatar answered Sep 23 '22 19:09

Tomas Petricek