Bug 21905 - Default HttpClient(.Net) fails for iOS 6.0
Summary: Default HttpClient(.Net) fails for iOS 6.0
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: master
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-08-07 08:30 UTC by Mustafa Shaik
Modified: 2014-12-05 12:27 UTC (History)
2 users (show)

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

Default HttpClient fails on iOS6 (deleted)
2014-08-07 08:30 UTC, Mustafa Shaik

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 or GitHub 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:

Description Mustafa Shaik 2014-08-07 08:30:14 UTC
Created attachment 7616 [details]
Default HttpClient fails on iOS6

On using default HttpClient fails on iOS6 with the following exception details. Please find the attached sample to demonstrate the same.

Loaded assembly: /private/var/mobile/Applications/9B89605C-0CAA-428F-B81B-4518F86077FF/iOSCoreTest.app/monotouch.dll [External]
Thread started:  #2
Loaded assembly: /private/var/mobile/Applications/9B89605C-0CAA-428F-B81B-4518F86077FF/iOSCoreTest.app/System.dll [External]
Loaded assembly: /private/var/mobile/Applications/9B89605C-0CAA-428F-B81B-4518F86077FF/iOSCoreTest.app/System.Core.dll [External]
Loaded assembly: /private/var/mobile/Applications/9B89605C-0CAA-428F-B81B-4518F86077FF/iOSCoreTest.app/System.Net.Http.Primitives.dll [External]
Loaded assembly: /private/var/mobile/Applications/9B89605C-0CAA-428F-B81B-4518F86077FF/iOSCoreTest.app/System.Net.Http.dll [External]
Loaded assembly: /private/var/mobile/Applications/9B89605C-0CAA-428F-B81B-4518F86077FF/iOSCoreTest.app/iOSCoreTest.exe
Resolved pending breakpoint at '/Volumes/HDD/Working/Projects/Tesco/TFS/Ccube/Samples/SendAsyncCoreTest/APIFails/iOSCoreTest-Individual/CoreTest/CoreTestViewController.cs:72,1' to System.Net.Http.HttpClient CoreTest.CoreTestViewController.GetHttpClient () [0x00018].
2014-08-07 13:26:06.132 iOSCoreTest[366:907] SendAsync start...
Thread started: <Thread Pool> #3
Thread started: <Thread Pool> #4
Thread started: <Thread Pool> #5
2014-08-07 13:26:06.962 iOSCoreTest[366:907] Exception Details: 
Message: Operation is not valid due to the current state of the object
Stacktrace:   at System.Lightup.Call[HttpWebRequest,Int64] (System.Delegate& storage, System.Net.HttpWebRequest instance, System.String methodName, Int64 parameter) [0x00000] in <filename unknown>:0 
  at System.Lightup.Set[HttpWebRequest,Int64] (System.Delegate& storage, System.Net.HttpWebRequest instance, System.String propertyName, Int64 value) [0x00000] in <filename unknown>:0 
  at System.Net.HttpWebRequestLightup.SetContentLength (System.Net.HttpWebRequest instance, Int64 value) [0x00000] in <filename unknown>:0 
  at System.Net.Http.HttpWebRequest.set_ContentLength (Int64 value) [0x00000] in <filename unknown>:0 
  at System.Net.Http.HttpClientHandler.StartRequest (System.Object obj) [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62 
  at System.Runtime.CompilerServices.TaskAwaiter`1[System.Net.Http.HttpResponseMessage].GetResult () [0x00000] in <filename unknown>:0 
  at CoreTest.CoreTestViewController+<ExecuteQuery>c__async0.MoveNext () [0x000d3] in /Volumes/HDD/Working/Projects/Tesco/TFS/Ccube/Samples/SendAsyncCoreTest/APIFails/iOSCoreTest-Individual/CoreTest/CoreTestViewController.cs:46
Comment 1 Mustafa Shaik 2014-08-07 08:32:07 UTC
Looks like I must use CFNetworkHandler instead of default HttpClient incase of iOS6 or any iOS. Can anyone comment on the same?

client = new HttpClient(); // Fails

client = new HttpClient(new CFNetworkHandler()); // Works fine.
But one must include system.net.http from xamarin.ios.

Comment 2 Sebastien Pouliot 2014-08-07 08:53:07 UTC
> Stacktrace:   at System.Lightup.Call[HttpWebRequest,Int64] (System.Delegate&

The type `System.Lightup.Call` is not part of any assemblies that are shipped with Xamarin.iOS. 

It looks like you're including the MS (or Nuget) version of System.Net.Http.dll. Are you building this from Windows ?

> Looks like I must use CFNetworkHandler

You can, there are several advantages (it's native to iOS), but it's not a *must*.

> But one must include system.net.http from xamarin.ios.

Yes, you must use the XI supplied assemblies (for the BCL). 

The BCL assemblies from MS requires dependencies (on the BCL) that are undocumented (and not part of XI).
Comment 3 Sebastien Pouliot 2014-09-03 14:16:18 UTC
The attached solution has the MS version of System.Net.Http.dll, not the version shipped by Xamarin. This is not supported since the internals are different.
Comment 4 Bojan Rajkovic [MSFT] 2014-12-05 12:27:30 UTC
The content of attachment 7616 [details] has been deleted by
    Bojan Rajkovic <bojan.rajkovic@xamarin.com>
who provided the following reason:

Tesco requested deletion.

The token used to delete this attachment was generated at 2014-12-05 12:27:17 EST.