Question

I'm using Microsoft HTTP Client Libraries - PCL (installed via NuGet) to communicate with a public REST API. Because I'm behind a corporate firewall, I need to configure the proxy info on the HttpClientHandler.

However, when setting proxy on the HttpClientHandler, it throws the following error:

Method not found: 'Void System.Net.Http.HttpClientHandler.set_Proxy(System.Net.IWebProxy)'.

There's nothing special about my code, so I am a bit puzzled:

var handler = new HttpClientHandler
{
    UseDefaultCredentials = false,
    Proxy = new DefaultProxy
    {
        Credentials =
            new NetworkCredential(
                "firstname.lastname",
                "P4ssw0rd",
                "DOMAIN")
    },
    UseProxy = true
};

this.client = new HttpClient(handler);

Some notes:

  • I've successfully used the HttpClientHandler from the standard .Net library (i.e. not PCL) for another project, so I know the proxy information is correct.
  • I've successfully retrieved the data when the proxy is bypassed (i.e. outside the corporate network, or no proxy).
  • DefaultProxy implements IWebProxy.
Was it helpful?

Solution

This error is due to the HttpClient package not being installed on the consuming project. You should be getting a warning similar:

All projects referencing [consuming project] must install nuget package Microsoft.Bcl.Build.

Basically, every referencing a class library that references HttpClient & Async must also reference HttpClient & Async.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top