c# - 错误 CS0433 : The type 'JsonValue' exists in both 'System.Json, Version=2.0.5.0' and 'Xamarin.Auth' (CS0433)

标签 c# json xamarin.forms xamarin.auth system.json

我正在尝试使用 Xamarin.Forms 在 Visual Studio for mac 中创建一个应用程序。在此应用中,我使用 Xamarin.Auth 来存储一些用户详细信息。现在我想使用 JSON 添加与 API 的连接。我添加了 System.Json 并添加了我的代码。但问题是我得到了错误:

Error CS0433: The type 'JsonValue' exists in both 'System.Json, Version=2.0.5.0' and 'Xamarin.Auth' (CS0433).

我在项目中删除并添加了 Xamarin.Auth。我在 visual studio 关闭时删除了 OBJ 和 BIN 文件夹,启动 VS,清理解决方案,重建解决方案并再次尝试,但仍然出现相同的错误。我似乎无法找出问题所在。

我不太确定它是否有帮助,但这是发生错误的代码片段,我知道该函数目前不返回任何内容,但我只是想弄清楚如何做 JSON/API 调用并获取代码以无错误地编译:

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;
    }

最佳答案

我在创建引用 Xamarin.Auth 和其他一些 NuGet 包以及 Facebook Xamarin 组件的 Xamarin Android 项目时遇到了同样的问题。我能够简单地从我的项目引用中删除 System.Json,然后我的项目就能够编译和运行。

关于c# - 错误 CS0433 : The type 'JsonValue' exists in both 'System.Json, Version=2.0.5.0' and 'Xamarin.Auth' (CS0433),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47147425/

相关文章:

C# 正则表达式匹配

php - 使用 Laravel 在 Json 列中搜索

c# - 带截断的多行标签

java - 为什么 JsonParser 使用 com.google.gson API 在返回值中给出双引号

Xamarin iOS HttpClient 超时不起作用

c# - 如何将 ListView 项目绑定(bind)到页面的 Viewmodel?

c# - 参数类型 'A' 不能分配给类型 'B'?

c# - 网络 API 2 : get profile data during oauth RegisterExternal (facebook)

c# - 如何重构以通过 try/multiple catch 减少嵌套深度 (NDepend)

ios - TableView 重新加载过早