- I created in VS Code a new classlib project.
- I added two packages to my project:
PowerShellStandard.Library
+System.Text.Json
.
My csproj
file contains this block:
<ItemGroup>
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" />
<PackageReference Include="System.Text.Json" Version="4.7.0" />
</ItemGroup>
My .cs
file uses System.Text.Json
and System.Management.Automation
.
It does not throw me any error/warning in VS Code when I use JsonSerializer.Serialize(...)
. It also compiles without errors or warning when runningdotnet build
. I can import it but, finally, when I run the code I receive the following error:
Get-JsonString : Could not load file or assembly 'System.Text.Json, Version=4.0.1.0, 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 am I missing here?
System.Text.Json
library as the version in the error message does not match thePackageReference
version – DisentitleSystem.Text.Json --version 4.0.1
but it added version 4.6. Afterwards, I received the same error message. I tried to useNewtonSoft.Json
. Even though I added this package to my csproject file VS Code throws the warning that NewtonSoft does not exist in the current context or that the namespace could not be found. @PavelAnikhouski, I want to compile PowerShell functions with C# and want to write it for .NET Core. – Dun