Search code examples
jsonf#type-providers

JsonProvider unusable


Trying to use the json type provider, unsuccesfully. After runnings the following commands :

  • Install-Package Newtonsoft.Json
  • Install-Package FSharp.Data -Version 2.2.5

I can't seem to be able to make the following error go away : JsonProvider is undefined

open FSharp.Data
open Microsoft.FSharp.Data.TypeProviders

type JsonObj =  JsonProvider<"http://shopicruit.myshopify.com/products.json">

I'd like to know what's currently missing because I can't see why this F# snippet is not right.

UPDATE

Here's a capture of my installs

enter image description here

enter image description here

Here's a capture of my type provider settings. (They were already enabled). I don't get what I'm missing at the moment...

enter image description here


Solution

  • When installing a NuGet Package to a project via the Package Manager Console, make sure that the value in the "Default project" field is the project you want to install the package to: Package Manager Console

    This has happened to me many times, including while trying to reproduce your issue. Also, as @Tomas Petricek says in the comments - both to your question and to my previous attempt at an answer here - you don't need to open Microsoft.FSharp.Data.TypeProviders. JsonProvider works with just a reference to FSharp.Data.

    In case you mistakenly installed the package to the wrong project, you can either:

    • Use Uninstall-Package to remove it, again making sure the "Default project" field targets the project in question, or;
    • Right-click on "References" under said project, then pick "Manage NuGet Packages". This will open the NuGet Package Manager window, from which you can also uninstall whatever you don't need.

    NuGet Package Manager