VS2022 17.9.3 C# interactive window, cannot use System.Text.Json

54 views Asked by At

I get the following errors if I run Json import code in C# Interactive

From VS2022, View->Other Windows->C# interactive

Anyone knows how to import the libraries in C# interactive to get this to work, current version:

Microsoft (R) Visual C# Interactive Compiler version 4.9.0-3.24121.1 ()

> using System;
. using System.Text.Json;
(2,19): error CS0234: The type or namespace name 'Json' does not exist in the namespace 'System.Text' (are you missing an assembly reference?)
> var x = 500m;
> JsonSerializer.Serialize(x)
(1,1): error CS0103: The name 'JsonSerializer' does not exist in the current context
1

There are 1 answers

3
Sani Huttunen On
  • Add the Nuget package System.Text.Json to your project.
  • Find the path to the .dll (can be seen in the properties window of the package, I.e.

C:\Users\xxx\.nuget\packages\system.text.json\8.0.3\lib\net8.0\System.Text.Json.dll

  • Reference the assembly in the C# Interactive window: #r <path_to_dll>