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

Created on 2 Apr 2017  路  6Comments  路  Source: JamesNK/Newtonsoft.Json

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]

Most helpful comment

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?

All 6 comments

It is marked as obsolete in Json.NET 10. It will be removed but not until the next major version.

@JamesNK thanks for the reply! When will be the next major version release?

6 months? A year? I'm not sure.

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?

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.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

azzlack picture azzlack  路  38Comments

Phreak87 picture Phreak87  路  11Comments

TylerBrinkley picture TylerBrinkley  路  37Comments

schani picture schani  路  11Comments

TylerBrinkley picture TylerBrinkley  路  16Comments