Newtonsoft.json incompatibility with Core 1.0 on .Net Framework?
I upgraded my RC2 packages to the release packages and am running into an issue with Newtonsoft.json.
I'm targeting the 4.6 framework only, not the cross platform framework (this project has lots of legacy assemblies).
Packages such as Microsoft.Extensions.Configuration.Json in the nuget tool says it needs newtonsoft.json 8.0.3 or higher (8.0.3 worked fine with RC2). However after installation this dependency (and many others) has a chain of dependencies with ends with "NU1012 Dependency conflict. Microsoft.Asp.NetCore.JsonPatch 1.0.0 expected Newtonsoft.Json >= 9.0.1 but got 8.0.3".
9.0.1 won't seem to install in this solution. Looking at that package, it seem to only support .NETStandard, Version 1.3 and not the .NetFramework 4.x
So I'm stuck. The new packages seem to have a dependency on something that doesn't run on the 4.6 framework.
Microsoft.Extension.Configuration.Json depends on Newtonsoft.Json 9.0.1 - https://www.nuget.org/packages/Microsoft.Extensions.Configuration.Json/ Did you update the version of tools from preview1 to preview2? Can you show your project.json?
Yes. Here is my project.json, with the RTE below. Note that the assembly that ends up in win7-x64 is newtonsoft.json 8.0.3.
{
"dependencies": {
"AutoMapper": "5.0.0-beta-1",
"EntityFramework": "6.1.3",
"Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0",
"Microsoft.AspNetCore.Authorization": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Identity": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Mvc.ApiExplorer": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Newtonsoft.Json": "9.0.1",
"NLog.Extensions.Logging": "1.0.0-2016-05-21",
"Swashbuckle": "6.0.0-beta9",
"System.Runtime.Extensions": "4.0.10"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview2-final"
}
},
"frameworks": {
"net461": {
"dependencies": {
"MPP.Api.Auth": {
"target": "project"
},
"MPP.Common.Business": {
"target": "project"
},
"MPP.Common.Data.EF": {
"target": "project"
},
"MPP.Common.PaymentGateway": {
"target": "project"
},
"MPP.Common.Resources": {
"target": "project"
}
},
"frameworkAssemblies": {
"System.Configuration": "4.0.0.0" }
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"xmlDoc": false
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config",
"nlog.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
System.IO.FileLoadException was unhandled by user code
FileName=Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
FusionLog==== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
(Fully-specified)
LOG: Appbase = file:///P:/MyCoreProject/nxt/wallet/wallet/src/wallet/bin/Debug/net461/win7-x64/
LOG: Initial PrivatePath = NULL
Calling assembly : Microsoft.Extensions.Configuration.Json, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: P:\MyCoreProject\nxt\wallet\wallet\src\wallet\bin\Debug\net461\win7-x64\wallet.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: Attempting download of new URL file:///P:/MyCoreProject/nxt/wallet/wallet/src/wallet/bin/Debug/net461/win7-x64/Newtonsoft.Json.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
HResult=-2146234304
Message=Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source=Microsoft.Extensions.Configuration.Json
StackTrace:
at Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider.Load(Stream stream)
at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
at wallet.Startup..ctor(IHostingEnvironment env) in P:\MyCoreProject\nxt\wallet\wallet\src\wallet\Startup.cs:line 41
InnerException:
What's what sometimes seems very confusing to me, but my read of the newtonsoft.json package 9.0.1 dependencies section reads "no soup for you" on the full framework.

That means it has no dependencies on that target framework
The first thing I found is that you depend on a version of NLog.Extensions.Logging that depends on RC2 version of ASP.NET Core. As a result you end up mixing 1.0.0 and RC2 packages. I can see that the 1.0.0-rtm-alpha1 version which depends on 1.0.0 packages is now available (https://www.nuget.org/packages/NLog.Extensions.Logging/1.0.0-rtm-alpha1). I was able to restore the project successfully after I moved to this version. I am not sure why you need a reference to System.Runtime.Extensions and/or if the version you have is correct. With the version you provided I received a lot of downgrade warnings:
warn : Detected package downgrade: System.Runtime.Extensions from 4.1.0 to 4.0.10
warn : test (>= 1.0.0) -> Microsoft.AspNetCore.Mvc (>= 1.0.0) -> Microsoft.AspNetCore.Mvc.ViewFeatures (>= 1.0.0) -> Microsoft.AspNetCore.Mvc.Core (>= 1.0.0) -> Microsoft.AspNetCore.Mvc.Abstractions (>= 1.0.0) -> Microsoft.Net.Http.Headers (>= 1.0.0) -> System.Runtime.Extensions (>= 4.1.0)
Note I commented out your project references otherwise I was not able to restore anything. You need to make sure that these project don't bring RC2 packages.
I upgraded NLog but i'm still getting 8.0.3 in my output. The other dependencies are plain old .net 4.5 libraries. Some of them do reference 8.0.3. New and improved DLL hell.
I can only assume this is being brought by one of your project references (i.e. Mpp* projects). I did not see any restore errors nor Newtonsoft.Json 8.0.3 in my project.lock.json after I moved NLog.Extensions.Logging to the rtm version.
I updated it on one (of several) projects and it's working. Other projects still reference 8.0.3. Very strange. I also removed swagger for now. I imagine things will settle down as people catch up to RTM. Thanks for the pointers.
I had issues with Newtonsoft.Json both on my development and Azure kudu deployment. Manually deleting bin/ folder solved the issue for me (I also had to delete repository folder on Azure). Could you try this? It might work for your case too.
I gave that a shot but it didn't help. I also need to find a way to bend nuget to my will - packages go where I tell them to go - and don't check them in!
Is there not a means in .NET Core to (like win Web/App.config) to specify a forced version upgrade via the configuration/runtime/assemblyBinding/dependentAssembly/bindingRedirect tag?
@h3smith - are you trying to version of a package higher than the one referenced by your dependencies? If so, add it to your project.json. Restore should bring that version in and take care of wiring up redirects for you.
Had the same issue. Even after revert to RC2. This helped as I remember
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
},
Looks like if you use some library that was built with RC2 you won't be able to run with some strange errors.
Adding to this that in RC2 MS Extensions used internally two different versions of Newtonsoft. Better to abandon RC2 altogether. Upgrading to RTM and Newtonsoft 9 cured my JSON problems.
I think, that sort nuget packages by folder with different versions was better idea, than we see now
I had the same issue, because of Newtonsoft reference in a dependency library, after upgrading to the latest version of Newtonsoft, the problem resovled.
The people that are having problems, do you have a csproj involved?
David, I have strong example to reproduce this issue
- Create ASP.NET Core project
- Try to add "tweetsharp": "2.3.1" package. It's ok and when you open tweetsharp dependencies - you see Newtonsoft 9.0.1. Ok
- Create .NET Core library and retarget it to net46
- Add package "tweetsharp": "2.3.1" to this lib. In dependencies - you see Newtonsoft 5.6.0 (not 9.0.1)
- Add this library to references in ASP.NET project. Try to run it - and you catch exception in this line of code
Configuration = builder.Build();
I'm hitting an issue with NewtonSoft 9.0.1 as well, no csproj involved. VS2015 Update 3: File -> New Project -> ASP.Net Core Web Application -> Web API And then I added "NewtonSoft.Json": "9.0.1" to the project.json file.
Now there seems to be a conflict with Microsoft.AspNetCore.Mvc and Microsoft.Extensions.Configuration.Json that both state: "The dependency Newtonsoft.Json >= 9.0.1 could not be resolved."
The VS-solution-files are found in the attachment. CoreWebApp.zip
Added: A colleague was able to resolve this solution. Seems like my machine has some leftovers from RC1 or RC2. I will cleanup and try again.
Result: I uninstalled "Microsoft .NET Core 1.0.0 RC2 - SDK Preview 1" and also added "NewtonSoft.Json" by using the Nuget Package Manager, instead of editing the project.json file. Everything is now resolving like it should.
(So once you move one project/solution from RC2 to RTM, you have to move all projects. RC2 and RTM cannot live together on a single machine. Not a bad thing, but important to be aware of.)