[英]How to reference System.Net.Http in WP8?
I am relatively new to WP8 development and have come across a problem that i just cannot figure out, even after hours of googling. 我是WP8开发的新手,遇到了一个问题,即使经过数小时的搜索,我也无法解决。
I am using visual studio 2012 and have implemented System.Net.Http using NuGet, have checked references, copy local is set to true, but it will not build. 我正在使用Visual Studio 2012,并已使用NuGet实现了System.Net.Http,已检查了引用,将local复制设置为true,但无法构建。
This is the error message which greets me: 这是我的错误消息:
CA0001 Error Running Code Analysis CA0001 : The following error was encountered while reading module '3D Protect Premium': Could not resolve member reference: [System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]System.Net.Http.HttpClient::PostAsync. [Errors and Warnings] (Global)
How do i fix this so the referenced version is correct?? 我如何解决此问题,以便引用的版本正确?
Edit 编辑
Code added below. 下面添加了代码。 This doesnt seem to be problematic, its just the referencing - i think its me misunderstanding to be honest, i Just dont have a clue whats going on with the System.Net.Http assembly!!
这似乎没有问题,仅是引用-老实说,我认为这是我的误解,我只是不知道System.Net.Http程序集发生了什么!
//Creates a new HttpClient Instance
var client = new HttpClient();
// This is the postdata
// Data forms an array and is used to populate the remote MySQL DB
var postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("name", "windowsphonetest"));
postData.Add(new KeyValuePair<string, string>("latitude", LatitudeString));
postData.Add(new KeyValuePair<string, string>("longitude ", LongitudeString));
postData.Add(new KeyValuePair<string, string>("devID", "test"));
HttpContent content = new FormUrlEncodedContent(postData);
//The actual HTTP Transaction
client.PostAsync("http://blah.com", content).ContinueWith(
(postTask) =>
{
postTask.Result.EnsureSuccessStatusCode();
});
您尝试使用的System.Net.Http
包已弃用,但您可以改用Microsoft.Net.Http 。
Solution: Delete all dependent NuGet packages, cleaning solution, deleting references to System.Net.* assemblies. 解决方案:删除所有相关的NuGet程序包,清洗解决方案,删除对System.Net。*程序集的引用。
Install Microsoft.Net.Http and its dependencies as suggested by NuGet. 根据NuGet的建议安装Microsoft.Net.Http及其依赖项。 Then install Microsoft.Bcl.Async - this is a dependency which is not flagged by NuGet (thanks keyboardP)
然后安装Microsoft.Bcl.Async-这是NuGet未标记的依赖项(感谢keyboardP)
Now go into project properties and disable 'Code analysis on build' - this tool is tripping up over the version number for some reason. 现在进入项目属性并禁用“构建时的代码分析”-由于某种原因,此工具超出了版本号。 Now the code builds and deploys fine.
现在,代码可以很好地构建和部署。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.