question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ambiguous type 'FormatterAssemblyStyle' when using Json.NET 10.0.1 with netcoreapp2.0 or netstandard2.0

See original GitHub issue

Newtonsoft.Json defines System.Runtime.Serialization.Formatters.FormatterAssemblyStyle in it, while this type is brought back in NetStandard2.0 in System.Runtime.Serialization.Formatters.dll. So when using this type in a project that targets netcoreapp2.0 or netstandard2.0 and references Json.NET 10.0.1, you will get the following error at compilation:

Program.cs(18,31): error CS0433: The type 'FormatterAssemblyStyle' exists in both 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' and 'System.Runtime.Serialization.Formatters, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' [D:\apps\netcore2\test\test.csproj]

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
abockcommented, Oct 11, 2017

We are now running into this in Xamarin Workbooks trying to port from some rather involved [Serializable], ISerializable, IObjectReference, SerializationBinder code to Newtonsoft.Json now that we can move all of our targets to netstandard2.0.

Given that targeting netstandard2.0 will provide the type, I do not see why you could not remove your version in the netstandard2.0 copy of Newtonsoft.Json.dll as part of the 10.x major release series?

1reaction
tmitchel2commented, Oct 23, 2017

In case anyone else is trying to use this assembly in a NetStandard2.0 libary, here are the options:

  • Use an assembly Alias so that two types with the same namespace and assembly can co-exist and be referenced. Not currently possible, has a DEPENDENCY ON https://github.com/NuGet/Home/issues/4989
  • Remove Newtonsoft.Json and use something else
  • Use explicit int values such as 0 and 1 instead of the enum values.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Newtonsoft.Json dependency in a .Net Standard 2 ...
I've experienced the same problem. I am maintaining an asp.net core 2.0 project which references two nuget packages, which I also maintain.
Read more >
Package Newtonsoft.Json 10.0.1 is not compatible with ...
The solution opens and it tries to restore packages, and then I get this error. I've uninstalled all Visual Studio installations and .NET...
Read more >
Migrate from Newtonsoft.Json to System.Text.Json - .NET
Learn about the differences between Newtonsoft.Json and System.Text.Json and how to migrate to System.Text.Json.
Read more >
Newtonsoft.Json 13.0.3
Json.NET is a popular high-performance JSON framework for .NET.
Read more >
Newtonsoft Json package
0 -preview.12 has newtonsoft JSON in its .Runtime forlder, which is causing issues when using something that depends on the com.unity.nuget.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found