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?
I had this issue because I had a dependency on Microsoft.Extensions.Configuration.Json in project B that targeted netstandard. Microsoft.Extensions.Configuration.Json requires System.Text.Json when starting .NETStandard, but not dotnetcore.
My problem came when in project A that targeted dotnetcore3.1 referenced project B. At runtime, AWS Lambda was still expecting System.Text.Json to be there.
To resolve the issue, I ended up switching project B to target dotnetcore3.1 as well, even though it is a pure library and not something executable.
Not sure this answers your question directly as I don't fully understand your situation, but a possible solution for this scenario. It was a little difficult finding many other resources on this issue but I probably just don't know what to look for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With