PowerShellStandard.Library
+ System.Text.Json
.我的 csproj
文件中包含这个区块。
<ItemGroup>
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" />
<PackageReference Include="System.Text.Json" Version="4.7.0" />
</ItemGroup>
我的 .cs
文件使用 System.Text.Json
和 System.Management.Automation
.
在VS Code中,当我使用 JsonSerializer.Serialize(...)
. 它在编译时也没有错误或警告,当运行dotnet build
. 我可以导入它,但最后,当我运行代码时,我收到以下错误。
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
我缺少什么?
我之所以出现这个问题,是因为我在项目B中对Microsoft.Extensions.Configuration.Json有一个针对netstandard的依赖。Microsoft.Extensions.Configuration.Json在启动.NETStandard时需要System.Text.Json,但不需要dotnetcore。
我的问题来了,当在以dotnetcore3.1为目标的项目A中引用项目B时,在运行时,AWS Lambda仍然期待System.Text.Json的存在。
为了解决这个问题,我最后把项目B也换成了以dotnetcore3.1为目标的项目,尽管它是一个纯库而不是可执行的东西。
不知道这能不能直接回答你的问题,因为我并不完全了解你的情况,但对这种情况提供了一个可能的解决方案。在这个问题上找到很多其他资源有点困难,但我可能就是不知道该找什么。