【问题标题】:HttpClient error when using System.Net.Http使用 System.Net.Http 时出现 HttpClient 错误
【发布时间】:2017-10-02 00:13:45
【问题描述】:

我收到以下错误

Error CS0246: The type or namespace name 'HttpClient' could not be found (are you missing a using directive or an assembly reference?) (CS0246)

但是,我的 using System.Net.Http 没有抛出错误。

我正在使用 Xamarin - 都是最新的。

我已经清理了我的项目,更新了我的所有 NuGet,并确保我的项目包含 Microsoft.Net.Http 包。

我的目标是我的 iOS 项目。

引用如下

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Net.Http;
using Newtonsoft.Json;
using Xamarin.Forms;

编辑:主要项目包中缺少参考 - 我该如何解决这个问题?

编辑:.Net 程序集参考

【问题讨论】:

  • 也许它想要 System.net insterd?
  • 我同时引用了 System.Net 和 System.Net.Http。 :(
  • 您的 System.Net.Http 是否在 PCL(Xamarin 项目)中?
  • 有时删除它们(右键单击 -> 删除)然后再次添加 nuget 包会有所帮助。

标签: c# xamarin xamarin.ios xamarin.forms xamarin.mac


【解决方案1】:

检查点: 转到两个项目(PCL 和 iOS)的引用文件夹。右键单击并检查 System.Net.Http 是否在他们俩中。

它们的引用中都应该有 System.Net.Http。

【讨论】:

  • 我用我的主要项目引用的屏幕截图在上面进行了编辑。
  • 1.右键单击 References 文件夹 2. 选择 Edit References 3. 在 .NET 程序集选项卡下 - 添加 System.Net.Http 和 System.Net
  • 我在旁边看到 System.Net.Http,但是,当我选择它时,菜单就关闭了。太奇怪了。 :( 我在原始问题中添加了一张图片。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-09
  • 1970-01-01
  • 2020-07-20
相关资源
最近更新 更多