I have been learning F# recently, and one of the great things about it is the REPL, called F# Interactive.

I ran into a problem when I tried to reference the Newtonsoft.Json NuGet package in an .fsx file, like so:

#I @"C:\Users\Jon\.nuget\packages\"
#r @"Newtonsoft.Json\11.0.2\lib\netstandard2.0\Newtonsoft.Json.dll"

Those lines give no indication of any potential problems, but when I try to use JsonConvert.DeserializeObject to deserialize a JSON string, I get an ugly red squiggly with the following error message:

The type ‘Object’ is required here and is unavailable. You must add a reference to assembly ‘netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’.

Oh my. What to do?

I poked around a little bit on Google and Stack Overflow, but didn’t really find an easy fix, so I set out to find netstandard.dll on my local machine. After a few false starts, I just did an Explorer search in C:\Users\Jon\.nuget\packages\ for netstandard.dll and picked the most promising result.

I shift-right-clicked on the file to get the path and added it to my references in the .fsx file:

#I @"C:\Users\Jon\.nuget\packages\"
#r @"Microsoft.NETCore.App\2.1.0-rtm-26502-02\ref\netcoreapp2.1\netstandard.dll"
#r @"Newtonsoft.Json\11.0.2\lib\netstandard2.0\Newtonsoft.Json.dll"

And voilà! The ugly red squiggly disappeared, and my script ran correctly in FSI.

If you know of a more elegant solution, please contact me on Twitter (@jonsagara) and I’ll update this post.

I’ve heard rumors that the F# team will make it easier to reference NuGet packages in future versions of FSI. I can’t wait!

Version information:

Visual Studio 2017, 15.7.4
F# Interactive version 10.1.0 for F# 4.1
Newtonsoft.Json 11.0.2
.NET Standard 2.0
.NET Core 2.1