NewtonSoft.Json NuGet v11.0.1-beta3 not working wi

2019-08-24 01:31发布

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条回答
老娘就宠你
2楼-- · 2019-08-24 02:13

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>
查看更多
登录 后发表回答