简体   繁体   English

在Xamarin中创建PCL时,.Net可移植子集中缺少HttpClient

[英]HttpClient missing from .Net portable subset while creating PCL in Xamarin

I have created a Portable class library in Xamarin and want to use it for an android app. 我在Xamarin中创建了一个Portable类库,并希望将它用于Android应用程序。 I want to use the HttpClient within this PCL. 我想在这个PCL中使用HttpClient I have added the Microsoft Http Client libraries from the NuGet Package manager. 我已经从NuGet包管理器添加了Microsoft Http Client libraries I can now see the .Net portable subset added to my references. 我现在可以看到.Net portable subset添加到我的引用中。 But somehow I still cannot use the HttpClient and it does not show in the .Net portable subset as well. 但不知怎的,我仍然无法使用HttpClient ,也没有在.Net可移植子集中显示。

Also, my Current profile of the PCL is 4.0-Profile 158 . 此外,我的PCL的Current profile4.0-Profile 158 If I change the profile to 4.5, Xamarin crashes and does not open the solution 如果我将配置文件更改为4.5,Xamarin崩溃并且无法打开解决方案

Can anyone help me with this? 谁能帮我这个? Thanks 谢谢

The simple solution is to target .NET 4.5, Windows Store apps (Windows 8.1), Xamarin.iOS, and Xamarin.Android (4.5-Profile7). 简单的解决方案是针对.NET 4.5,Windows应用商店应用(Windows 8.1),Xamarin.iOS和Xamarin.Android(4.5-Profile7)。 Then you won't need the HttpClient NuGet package to get those APIs. 然后,您将不需要HttpClient NuGet包来获取这些API。

If Xamarin is crashing when you try to select a 4.5 profile, please make sure you're using the latest version and then report the bug with details about how to repro it and what happens. 如果当您尝试选择4.5配置文件时Xamarin崩溃,请确保您使用的是最新版本,然后报告错误,详细说明如何重新配置​​以及发生的情况。

Also the HttpClient NuGet package should allow you to use HttpClient from PCL profile 158. Make sure you're using the latest version of NuGet. 此外,HttpClient NuGet包应允许您使用PCL配置文件158中的HttpClient。确保您使用的是最新版本的NuGet。 ".NET Portable Subset" should always appear in your references for a PCL, that's not related to the NuGet package. “.NET Portable Subset”应始终出现在PCL的引用中,这与NuGet包无关。 When you install the HttpClient NuGet package, you should also see references to System.Net.Http and other assemblies in your references. 安装HttpClient NuGet包时,还应该在引用中看到对System.Net.Http和其他程序集的引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM