12

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?

Guvante
  • 18,775
  • 1
  • 33
  • 64
user2344035
  • 121
  • 1
  • 4
  • 1
    http://stackoverflow.com/questions/3102472/f-c-fsx-script-files-and-project-references An fsx file doesn't use project references (neither does fsi). You need to manually reference the files. See that post for assistance. – N_A May 02 '13 at 17:12
  • 1
    There is a more thorough writeup here: http://blogs.msdn.com/b/chrsmith/archive/2008/09/12/scripting-in-f.aspx – N_A May 02 '13 at 18:07
  • Thanks Chris. I've read several of your writeups, but not that one! – user2344035 May 02 '13 at 18:35
  • I'm not Chris, but I'm glad you like the link ;-) – N_A May 02 '13 at 19:17
  • Oops sorry, misread that. Thanks alot for that link. It's a big help. – user2344035 May 02 '13 at 20:14

2 Answers2

11

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"
jdearana
  • 1,089
  • 12
  • 17
  • The thing that threw me off is that VS gives me squiggly lines as soon as I start typing that (i.e. #r ""). It's actually parsing the string at design time. So when I finally found the dll, the squiggly line went away. – mac10688 Dec 21 '15 at 19:01
5

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..

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553