Bug 47806 - Setting the AndroidClientHandler in the Android app project properties has no effect.
Summary: Setting the AndroidClientHandler in the Android app project properties has no...
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Android ()
Version: 4.3.0 (C9)
Hardware: PC Windows
: Normal normal
Target Milestone: 4.3.0 (C9)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-11-24 01:18 UTC by Jon Goldberger [MSFT]
Modified: 2016-12-05 21:48 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Jon Goldberger [MSFT] 2016-11-24 01:18:33 UTC
## Description

Setting the AndroidClientHandler in the Android app project properties has no effect. I did find this internal, private bug report, bug #43749,  which says this is a linker issue and should be fixed in the C9 builds but I tested using the C9 builds in the Alpha channel and the setting still has no effect and I still get the
> I mono-stdout: Xamarin.Android returned no custom HttpClientHandler. Defaulting to System.Net.Http.HttpClientHandler
message. 

## Steps to reproduce.

1. Create a new Xamarin.Android Single View app project in Visual Studio

2. Open the MainActivity.cs file and add the following code to the OnCreate method:

>var c = new HttpClient();
>try
>{
>      var r = await c.GetAsync("https://www.xamsarin.com");
>
>      r.EnsureSuccessStatusCode();
>}
>catch (WebException ex)
>{
>      System.Diagnostics.Debug.WriteLine("WebException catch block:\r{0}", ex);
>}
>catch (Java.IO.IOException ex)
>{
>      System.Diagnostics.Debug.WriteLine("Java.IO.IOException catch block:\r{0}", ex);
>}
>catch (Exception ex)
>{
>      System.Diagnostics.Debug.WriteLine("Exception catch block:\r{0}", ex);
>}

3. Make sure to set the AndroidClientHandler in the Project Properties->Android Options->Advanced settings page.

4. Deploy the app to device or simulator.

Expected result: You will get an exception from the AndroidClientHandler output to the console, which will be a Java exception:
>Java.Net.UnknownHostException: Unable to resolve host "www.xamsarin.com": No address associated with hostname ---> Java.Lang.RuntimeException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)

Actual result: You get an exception from the managed mono http client handler:
>System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: NameResolutionFailure

## Workaround

Pass an instance of AndroidClientHandler to the new HttpClient instance. 

## Environment 

Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01586

Xamarin   4.3.0.281 (2c75d6d)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   7.1.0.2 (0a4ab55)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS   10.4.0.1 (7c50b27)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 2 Jon Goldberger [MSFT] 2016-12-05 21:48:53 UTC
Tested with the latest Alpha C9 builds and I can no longer reproduce this issue. I am now getting the exception noted in the expected results. 

Microsoft Visual Studio Enterprise 2015
Version 14.0.25425.01 Update 3
Microsoft .NET Framework
Version 4.6.01586

Xamarin   4.3.0.458 (60863b1)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   7.1.0.13 (72366f7)
Visual Studio extension to enable development for Xamarin.Android.