问题
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?
回答1:
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"
回答2:
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 azip
file and extract the file using Windows). To unblock the file, go to file properties and click "Unblock". There is a good description here..
来源:https://stackoverflow.com/questions/16343876/scripts-dont-recognize-fsharp-data