I have a project I have been working on using Xamarin's MonoDevelop.
I have been using Newtonsoft's Json nuget package.
I just downloaded Visual Studio 2017 for Mac.
I try to build my project in VS2017Mac and get the following error:
error CS0433: The type 'JsonConvert' exists in both 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' and 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
I thought I should be able to fix that by just adding Newtonsoft.Json. to the front of JsonConvert, but that didn't work.
I don't want to remove Newtonsoft's implementation if possible because I think their library still has more functionality. Is there another way to resolve this? Why didn't adding the full assembly reference work?
I had the following error message but with another library(Ranet) in C#:
Error CS0433 The type 'JsonConvert' exists in both 'Microsoft.AnalysisServices.Tabular.Json, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' and 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
I solved it using aliases, but I would like to provide a bit more detail as I struggled to implement using the instructions from these answers and other answers. This is how I did it:
extern alias Newton;
using NewtonReference = Newton::Newtonsoft.Json;
NewtonReference.JsonConvert.DeserializeObject<string>("");
extern alias Newton;
using System;
using NewtonReference = Newton::Newtonsoft.Json;
public class Test {
public static List<string> TestMethod() {
NewtonReference.JsonConvert.DeserializeObject<string>("");
}
}
Hopefully this will be helpful to someone else :)
In the Properties window for the project's Newtonsoft.Json reference, change the value of Aliases from global
to global, foo
.
Insert extern alias foo;
as the first line of any class that consumes Newtonsoft.Json.
Qualify members with foo.
. Example: foo.Newtonsoft.Json.JsonConvert.SerializeObject(someObject)}
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With