HttpClientHandler does not contain a definition for DefaultProxyCredentials
Why are you targeting 4.6 instead of 4.7.2? This matters and can lead to NuGet dependency hell.
It looks like you're using the (very) old HttpClient class included in 4.6 instead of the System.Net.Http package. That old implementation doesn't even use the new socket handler. The HttpClientHandler.DefaultProxyCredentials property was added in .NET 4.7.1.
- The best option is probably to target the latest .NET version, or at least 4.7.1 and use the same code you do now. Better yet, target 4.7.2 to avoid the dependency shim hell explained in the next option.
- You could just add the package. It's the same .NET Standard 2.0 package used in .NET Core projects. The downside to that is that 4.6.1 is not really .NET Standard 2.0 compatible and requires several compatibility libraries. Upgrading can easily lead to dependency hell as versions conflict with one another. The .NET team admitted that trying to retrofit .NET Standard 2.0 compliance was a bad idea
While NuGet considers .NET Framework 4.6.1 as supporting .NET Standard 1.5 through 2.0, there are several issues with consuming .NET Standard libraries that were built for those versions from .NET Framework 4.6.1 projects. For .NET Framework projects that need to use such libraries, we recommend that you upgrade the project to target .NET Framework 4.7.2 or higher.
Been there. Have the production crash reports to prove it. And the premium 1 day upgrade experience of removing all previous shims to get rid of version conflicts. Several issues
indeed
- Set the Credentials property of the default proxy with
WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultNetworkCredentials;