NewtonSoft.Json NuGet v11.0.1-beta3 不适用于 .Net Standard 2.0 [英] NewtonSoft.Json NuGet v11.0.1-beta3 not working with .Net Standard 2.0

查看:21
本文介绍了NewtonSoft.Json NuGet v11.0.1-beta3 不适用于 .Net Standard 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Visual Studio 2017 15.5.5,我创建了一个 .NET Standard (2.0) 类库.

Using Visual Studio 2017 15.5.5, I created a .NET Standard (2.0) Class Library.

为此,我添加了 NuGet 包Newtonsoft.Json v11.0.1-beta3"(最新的完整版似乎不支持 .NET Standard 2.0).当我转到包位置时,看到以下文件:

To this, I added the NuGet package "Newtonsoft.Json v11.0.1-beta3" (the latest full version does not seem to support .NET Standard 2.0). When I go to the package location, I see the following file:

~.nugetpackages ewtonsoft.json11.0.1-beta3lib etstandard2.0Newtonsoft.Json.dll

~.nugetpackages ewtonsoft.json11.0.1-beta3lib etstandard2.0Newtonsoft.Json.dll

但是,在执行代码时(仅在 RELEASE 模式下),我得到以下异常:

However, when executing the code (in RELEASE mode only), I get the following exception:

System.IO.FileNotFoundException:无法加载文件或程序集'Newtonsoft.Json,版本=11.0.0.0,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed' 或其依赖项之一.这系统找不到指定的文件.

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

我的项目文件包含:

<ItemGroup>
  <PackageReference Include="Newtonsoft.Json" Version="11.0.1-beta3" />

我可以让它工作的唯一方法是卸载 NuGet 包,然后直接引用 DLL.这显然不是很令人满意,因为 NuGet 提供了如此多的优势.

The only way I could get this to work was to un-install the NuGet package and then reference the DLL directly. This is obviously not very satisfactory since NuGet offers so many advantages.

建议?

编辑发现这仅在 RELEASE 模式下表现出来.在 DEBUG 模式下,所有单元测试都通过.

EDIT Discovered that this only manifests itself in RELEASE mode. In DEBUG mode, all unit tests pass.

推荐答案

尝试添加 dependentAssembly 到您的 app.config 文件.

Try to add dependentAssembly to your app.config file.

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>

这篇关于NewtonSoft.Json NuGet v11.0.1-beta3 不适用于 .Net Standard 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆