JsonConvert Exists in both Newtonsoft and System.Net.Http.Formatting Visual Studio 2017 for Mac

  1. In the Properties window for the project's Newtonsoft.Json reference, change the value of Aliases from global to global, foo.

  2. Insert extern alias foo; as the first line of any class that consumes Newtonsoft.Json.

  3. Qualify members with foo.. Example: foo.Newtonsoft.Json.JsonConvert.SerializeObject(someObject)}.


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:

  1. In the solution explorer, right click on the "Newtonsoft.json", add ", Newton" to the alias field, it should look something like this:

enter image description here

  1. Add the following code to the first line of you file(before all using statements):
extern alias Newton;
  1. Add the following reference to the end of your using statements:
using NewtonReference = Newton::Newtonsoft.Json;
  1. Now you can call Newtonsoft method using the following code:
NewtonReference.JsonConvert.DeserializeObject<string>("");
  1. A final example would look something like this:
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 :)