I'm trying to create an app in Visual studio for mac with Xamarin.Forms. In this app I'm using Xamarin.Auth to store some user details. Now I want to add a connection with an API by using JSON. I added System.Json and added my code. But the problem is I get the error:
Error CS0433: The type 'JsonValue' exists in both 'System.Json, Version=2.0.5.0' and 'Xamarin.Auth' (CS0433).
I removed and added Xamarin.Auth to the project. I removed the OBJ and BIN folders while visual studio was closed, started VS, cleaned the solution, rebuild the solution and tried it again but still the same error. I can't seem to find out what the problem is.
I'm not quite sure if it will help but here is one snippet of code where the error occurs, I know the function does not return anything at the moment but I'm just trying to figure out how to do JSON/API calls and get the code to compile without errors:
public class DBhandler
{
public async Task<List<Object>> GetItemsFromApiASync(Type callingClass, string apiDir, string apiFile)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(ApiAddress + apiDir + apiFile));
request.ContentType = "application/json";
request.Method = "Get";
using (WebResponse response = await request.GetResponseAsync())
{
using (Stream stream = response.GetResponseStream())
{
System.Json.JsonValue jsonDoc = await Task.Run(() => System.Json.JsonObject.Load(stream));
object[] parametersArray = new object[] { jsonDoc };
MethodInfo methodInfo = callingClass.GetMethod("ConvertApiResultToObject");
methodInfo.Invoke(methodInfo, parametersArray);
}
}
return null;
}
All of a sudden I did remember how to solve this: I was helped by the comments on the question(thanks @Tcraft, @DiegoRafaelSouza). I added System.Json
to the references on the different platforms(I use a shared project, so on project.IOS
and project.Android
). Right clicked on properties
and ticked Local Copy
. Then I added an alias SystemJsonAlias
. And used using SystemJsonAlias = System.Json
in all my .cs files where needed.
Perhaps this helps someone else.