Fix error "Could not load System.Text.Json"?

I have created a new classlib project in Visual Studio Code. The csproj file contains two packages: PowerShellStandard.Library, version 5.1.1, and System.Text.Json, version 4.7.0. My .cs file uses System.Text.Json and System.Management.Automation.

I am able to compile the code without errors or warnings when running dotnet build, but when I run the code I get the following error:

Get-JsonString : Could not load file or assembly 'System.Text.Json, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
At line:1 char:1
+ Get-JsonString -input s
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Get-JsonString], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,UrlCSharpPowerShell.CreateJson

What could be causing this error?

The error is caused by a version mismatch between the System.Text.Json package referenced in the csproj file (version 4.7.0) and the version of the assembly (version that the PowerShell cmdlet Get-JsonString is trying to load. To fix this issue, you should update the System.Text.Json package to version 5.0.0 or higher, which is compatible with .NET Standard 2.0 and should resolve the issue.