简体   繁体   中英

The type or namespace Http does not exist in the the namespace Flurl

Starting a new Portable Class Library project, I've added the Flurl.Http NuGet package , which appears to have also brought down all it's dependancies, as expected.

However when I add the using Flurl.Http directive and some simple code such as

using System.Threading.Tasks;
using Flurl;
using Flurl.Http;

public class ClientRepository
{
    public async Task<string> Connect()
    {
        var result = await "http://example.com"
            .AppendPathSegment("/login")
            .PostUrlEncodedAsync(new { username = "you", password = "password" }).ReceiveJson();
        return result.token;
    }
}

I get the compile error

The type or namespace name 'Http' does not exist in the namespace 'Flurl' (are you missing an assembly reference?)

What's odd that intellisense has no problem recognizing the .Http namespace, or the extension methods (PostUrlEncodedAsync)

What could I be missing from this most basic of PCL projects?

Perhaps my package.config file would be of value, so here it is as well:

<packages>
  <package id="Flurl" version="1.0.5" targetFramework="portable-net45+sl50+MonoAndroid10+xamarinios10+MonoTouch10" />
  <package id="Flurl.Http" version="0.4.1" targetFramework="portable-net45+sl50+MonoAndroid10+xamarinios10+MonoTouch10" />
  <package id="Microsoft.Bcl" version="1.1.9" targetFramework="portable-net45+sl50+MonoAndroid10+xamarinios10+MonoTouch10" />
  <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="portable-net45+sl50+MonoAndroid10+xamarinios10+MonoTouch10" />
  <package id="Microsoft.Net.Http" version="2.2.22" targetFramework="portable-net45+sl50+MonoAndroid10+xamarinios10+MonoTouch10" />
  <package id="Newtonsoft.Json" version="6.0.3" targetFramework="portable-net45+sl50+MonoAndroid10+xamarinios10+MonoTouch10" />
  <package id="PCLStorage" version="0.9.6" targetFramework="portable-net45+sl50+MonoAndroid10+xamarinios10+MonoTouch10" />
</packages>

I was able to reproduce using the combination of target platforms gleaned from your packages.config (very helpful). The problem appears to be with Silverlight 5. This was working at one point; my hunch is that support was dropped for it in one of the dependent libraries, though I've not yet confirmed that.

At any rate, if you can get by without SL5 support (and maybe you can't), I've confirmed that a new PCL targeting all the others that Flurl.Http is documented to support does build with your code:

Flurl.Http PCL支持

(Side note: I've run into issues trying to change PCL targets in existing projects - you might save yourself some headaches by starting with a clean slate.)

My apologies for any inconvenience. I'll update the list of supported targets in the docs . I welcome any suggestions/pull requests to get it working with SL5.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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