Поскольку он был совместим с .Net Standard 2.0 при использовании NuGet. пакет, я подумал, что попробую переключиться на System.Text.Json вместо использования NewtonSoft. Однако, похоже, у него нет той версии конкретных сборок, которая требуется на определенных платформах.
Моя среда:
Windows 10
PowerShell 5.1 для рабочего стола
.Net Framework 4.8
PowerShell Core 6.2.2
dotnet версии 3.0.100
В PowerShell Desktop я получаю следующие проблемы, когда приходится что-либо десериализовать:
Код: Выделить всё
PS dir:\> Import-Module '.\file.dll'
PS dir:\> [namespace.class]::TestMethod($string, $anotherString) # Test method to return string
{"attribute":"value"}
PS dir:\> [namespace.class]::Method($string, $anotherString) # Same as above, but uses System.Text.Json to deserialise
Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system
cannot find the file specified.
# System.Buffers.dll is with the System.Text.Json package, but seems to be the wrong version
PS dir:\> (Get-Item .\System.Buffers.dll).VersionInfo.FileVersion
4.6.26515.06
PS dir:\> [System.Reflection.Assembly]::LoadFile("$pwd\System.Buffers.dll").GetName().Version
Major Minor Build Revision
----- ----- ----- --------
4 0 3 0
Код: Выделить всё
PS dir:\> Import-Module '.\file.dll'
PS dir:\> [namespace.class]::Method($string, $anotherString)
"Could not load file or assembly 'System.Text.Encodings.Web, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)"
#System.Text.Encodings.Web.dll is with the System.Text.Json package and appears to be the required version...
PS dir:\> (Get-Item .\System.Text.Encodings.Web.dll).VersionInfo.FileVersion
4.700.19.56404
[System.Reflection.Assembly]::LoadFile("$pwd\System.Text.Encodings.Web.dll").GetName().Version
Major Minor Build Revision
----- ----- ----- --------
4 0 5 0
Заранее спасибо. Пожалуйста, дайте мне знать, если вам потребуется дополнительная информация, я ее предоставлю.
РЕДАКТИРОВАТЬ
Я обновил csproj, как предложил Гохан
Код: Выделить всё
true
true
Код: Выделить всё
Подробнее здесь: https://stackoverflow.com/questions/604 ... -text-json
Мобильная версия