How to use .NET Standard 2.0 NuGet packages with F# Interactive
Posted June 26, 2018
Reading time: 1 minute
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:
|
|
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:
|
|
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:
|
|