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
.当我使用
JsonSerializer.Serialize(...)
时,它不会在 VS Code 中抛出任何错误/警告.运行 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
我在这里缺少什么?
最佳答案
我遇到这个问题是因为我依赖于针对 netstandard 的项目 B 中的 Microsoft.Extensions.Configuration.Json。启动 .NETStandard 时,Microsoft.Extensions.Configuration.Json 需要 System.Text.Json,但不需要 dotnetcore。
我的问题出现在针对 dotnetcore3.1 引用项目 B 的项目 A 中。在运行时,AWS Lambda 仍然期望 System.Text.Json 存在。
为了解决这个问题,我最终将项目 B 也切换到了目标 dotnetcore3.1,即使它是一个纯库而不是可执行的东西。
不确定这是否能直接回答您的问题,因为我不完全了解您的情况,但是这种情况的可能解决方案。在这个问题上找到许多其他资源有点困难,但我可能只是不知道该寻找什么。
关于c# - 如何修复错误 "Could not load file or assembly ' System.Text.Json, ...”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59595684/