Search code examples
f#type-providers

Cannot instantiate any F# type provider from FSharp.Data


I'm attempting to recreate the simplest example possible for the CSV type provider:

  • I create a Library project in Visual Studio 2015, by default this targets F#4.0 and .NET 4.5.2.
  • I add FSharp.Data 2.2.5 via NuGet.

Already, I have one error and one warning in my project:

The type provider 'ProviderImplementation.JsonProvider' reported an error: The type provider constructor has thrown an exception: API restriction: The assembly 'file:///c:\users\james foye\documents\visual studio 2015\Projects\CsvExample\packages\FSharp.Data.2.2.5\lib\net40\FSharp.Data.dll' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain. CsvExample c:\users\james foye\documents\visual studio 2015\Projects\CsvExample\CsvExample\Library1.fs 1

and

Referenced assembly 'c:\users\james foye\documents\visual studio 2015\Projects\CsvExample\packages\FSharp.Data.2.2.5\lib\net40\FSharp.Data.dll' has assembly level attribute 'Microsoft.FSharp.Core.CompilerServices.TypeProviderAssemblyAttribute' but no public type provider classes were found CsvExample c:\users\james foye\documents\visual studio 2015\Projects\CsvExample\CsvExample\Library1.fs 1

All attempts to instantiate the provider fail, for example:

open FSharp.Data;;

let yahoo = CsvProvider<"sample.csv">;;

C:\Data\Ebooks\F#\Deep Dives\Source\Chap6\YahooProvider\stdin(4,13): error FS0039: The value or constructor 'CsvProvider' is not defined

It doesn't matter what I do to play around with the path (provide full path, change working directory of FSI, etc.)


Solution

  • I was not able to get to the bottom of the compiler error, it almost seems like a bug somewhere with Visual Studio, NuGet, or some other part of the tool chain. But as mpeac suggested, simply restarting VS cleared it.

    Once I did that I needed to change my code from declaring a let binding to defining a type. I had just mistakenly typed "let =" instead of "type =".