NewtonSoft.Json NuGet v11.0.1-beta3 not working with .Net Standard 2.0

可紊 提交于 2019-12-11 15:29:53

问题


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

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:

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

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

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.

My project file contains:

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

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.

Suggestions?

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


回答1:


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>


来源:https://stackoverflow.com/questions/48519796/newtonsoft-json-nuget-v11-0-1-beta3-not-working-with-net-standard-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!