I create HttpClient and call GetStringAsync method right at the button click handler:
var client = new HttpClient();
var response = await client.GetStringAsync("http://google.com");
Debug.WriteLine("Response received: {0}", response);
And every time I get the following error:
System.InvalidOperationException: Operation is not valid due to the current state of the object
2014-05-10 01:26:36.657 HelloWorld3[490:60b] Unhandled managed exception: Operation is not valid due to the current state of the object (System.InvalidOperationException)
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.ExceptionDispat
chInfo.Throw () [0x0000b] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62
at System.Runtime.CompilerServices.TaskAwaiter`1[System.String].GetResult () [0x00000] in <filename unknown>:0
at HelloWorld3.MyViewController+<<ViewDidLoad>b__0>d__1.MoveNext () [0x00029] in c:\Sources\Local\HelloWorld3\HelloWorld3\MyViewController.cs:41
Debugging session ended.
The program 'Mono' has exited with code 0 (0x0).
I'm not using portable libs, nugets, etc. Just plain project created from a template. How to solve this issue?
test project with reproduced issue here: https://dl.dropboxusercontent.com/u/19503836/HelloWorld3.zip