【问题标题】:NewtonSoft.Json NuGet v11.0.1-beta3 not working with .Net Standard 2.0NewtonSoft.Json NuGet v11.0.1-beta3 不适用于 .Net Standard 2.0
【发布时间】:2018-01-30 11:00:51
【问题描述】:

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

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

~.nuget\packages\newtonsoft.json\11.0.1-beta3\lib\netstandard2.0\Newtonsoft.Json.dll

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

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

我的项目文件包含:

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

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

建议?

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

【问题讨论】:

    标签: visual-studio json.net .net-standard


    【解决方案1】:

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

    <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>
    

    【讨论】:

    • DLL 没有 app.config 文件,因此创建了一个,但没有任何效果。我确实发现这只发生在 RELEASE 模式下。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    相关资源
    最近更新 更多