c# - Newtonsoft.JSON v9.01 + FileNotFoundException(.NET 核心类库)

标签 c# json.net .net-core

(VS2015 更新 3 + 补丁)

我有一个普通的 .NET 控制台应用程序 (.NET 4.6) 并引用了一个面向 NetStandard v1.3 的 .NET 核心类库。 类库引用了 Newtonsoft.JSON。

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.6.0",
    "Newtonsoft.Json": "9.0.1"
  },
  "buildOptions": { "platform": "anycpu" },

  "frameworks": {
    "netstandard1.3": {
      "imports": "dnxcore50"
    }
  }
}

引用的 NewtonSoft.JSON 包部署在这里:

C:\Users\UserAccount\.nuget\packages\Newtonsoft.Json\9.0.1

异常:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in DotNetConsoleApplication.exe

Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

我猜 .net 核心库会引用 netstandard1.0 文件夹中的 dll。

enter image description here

最佳答案

创建 NuGet 包是一种解决方案,但不是最简单的。

Microsoft 终于承认这是一个问题并且will fix它有望在 NuGet 版本 4.0.1 中出现,这是 VS 2017 发布后对 NuGet 4 的首次更新。

现在最干净的解决方法是添加 <RestoreProjectStyle>PackageReference</RestoreProjectStyle>到遗留项目。然而according to Rob Relyea MS 将在 RTM 之后忽略此属性,因此另一个解决方法是 <PackageReference Update="PlaceholderToConvinceThisProjectToGetTransitivePackageReferenceFromProjectReferences"/> .

关于c# - Newtonsoft.JSON v9.01 + FileNotFoundException(.NET 核心类库),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38349276/

相关文章:

C# 如何检测循环引用?

c# - winXP上的https请求错误

c# - 将代码与空格对齐时阻止 IDE0055 样式分析器

c# - 通过字典访问子对象的方法

c# - Json.net 只序列化某些属性

angular - Azure Web App HTTP 错误 414 - URL 请求太长

c# - 反序列化数组时如何获取对象json

c# - Json.NET 即使使用默认设置也将枚举序列化为字符串

c# - 如何在 .NET 核心中使用 .settings 文件?

c# - 按需输出使用 DragonFruit 的帮助