简体   繁体   中英

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

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM