Reputation: 4064
I'm having trouble resolving a missing reference when trying to use Json.NET's JsonConvert.DeserializeObject method in a Class Library Package targeting .NET Core.
To reproduce in VS2015:
In the default Class1 that's created, add this simple method:
public void DoSomething()
{
var x = JsonConvert.DeserializeObject("");
}
You'll get the following error:
The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0'
Any idea what reference I'm missing? I assume it's some kind of System.Serialization or System.IO package but I can't figure out which one.
project.json:
{
"version": "1.0.0-*",
"description": "ClassLibrary1 Class Library",
"authors": [ "DD" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"frameworks": {
"net451": { },
"netcore50": {
"dependencies": {
"Microsoft.CSharp": "4.0.0",
"System.Collections": "4.0.0",
"System.Linq": "4.0.0",
"System.Runtime": "4.0.0",
"System.Threading": "4.0.0"
}
}
},
"dependencies": {
"Newtonsoft.Json": "8.0.2"
}
}
Upvotes: 4
Views: 4500
Reputation: 12677
You can use latest Newtonsoft.Json nuget package (at the moment it's 11.0.2) working fine without any problem with .NET Core 2.1.
Upvotes: 2
Reputation: 3765
You can fix this issue by adding a dependency of Microsoft.NETCore.Portable.Compatibility
. [NuGet page]
{
"version": "1.0.0-*",
"description": "ClassLibrary1 Class Library",
"authors": [ "DD" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"frameworks": {
"net451": { },
"netcore50": {
"dependencies": {
"Microsoft.CSharp": "4.0.0",
"System.Collections": "4.0.0",
"System.Linq": "4.0.0",
"System.Runtime": "4.0.0",
"System.Threading": "4.0.0"
}
}
},
"dependencies": {
"Newtonsoft.Json": "8.0.2",
"Microsoft.NETCore.Portable.Compatibility": "1.0.1-beta-23516"
}
}
Upvotes: 3