Hello, everyone.
I have a problem with Android application I encountered in the end of february after Xamarin Studio update. I'm a beginner with android and xamarin, so I'm not sure if it's related to the update somehow. Then I was using API15. Now I updated through to the API 19, tried different APIs, and I still get it.
What I do is asking a simple POST-request with variables using HttpClient and HttpHandler:
var postDataDecision = new List<KeyValuePair<string,string>> () {
new KeyValuePair<string, string> ( "transaction_id", transactionId ),
new KeyValuePair<string, string> ( "client_id", clientId.ToString ())
};
HttpContent contentDecision = new FormUrlEncodedContent(postDataDecision);
response = httpClient.PostAsync( GetDecisionUrl(), contentDecision).Result;
response.EnsureSuccessStatusCode();
responseBodyAsText = response.Content.ReadAsStringAsync().Result;
First thing that happened is the Error 417. I fixed it easily with System.Net.ServicePointManager.Expect100Continue = false;
I was starting to get an error in the line "response.EnsureSuccessStatusCode();". It was saying "413 Request entity is too large", although I never faced it before. But I am pretty sure that this error now in the past, because it happened when I had MaxRequestContentBufferSize = 256000 or MaxResponseContentBufferSize = 256000, now I have increased both values to 8388608 to prevent it. (Still it worked with the 256000 values before! Again, I am not sure if this is an error because of the update, but the same code worked fine earlier.)
Now I get an error in the line "response = httpClient.PostAsync( GetDecisionUrl(), contentDecision).Result;" with unnamed exception "A system.aggreageexception was thrown" containing in the body following information:
{System.Net.WebException: Error getting response stream (ReadDone2): ReceiveFailure ---> System.Exception: at System.Net.WebConnection.HandleError(WebExceptionStatus st,...) at System.Net.WebConnection.ReadDone(IAsyncResult result)....}
I cannot copy & paste it because when I click on it I get this message:
Details of errors, along with anonymous installation information, can be sent to Xamarin to help improve Xamarin Studio. Do you wish to send this information?
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength)
at System.IO.Path.GetFullPathInternal(String path)
at System.IO.Path.GetFullPath(String path)
at MonoDevelop.Core.FilePath.get_FullPath()
at MonoDevelop.Projects.ProjectFileCollection.GetFile(FilePath path)
at MonoDevelop.Projects.Project.IsFileInProject(String fileName)
at MonoDevelop.Projects.SolutionFolder.GetProjectContainingFile(String fileName)
at MonoDevelop.Projects.Solution.GetProjectContainingFile(FilePath fileName)
at MonoDevelop.Ide.RootWorkspace.GetProjectContainingFile(String fileName)
at MonoDevelop.Debugger.ExceptionCaughtDialog.IsUserCode(ExceptionStackFrame frame)
at MonoDevelop.Debugger.ExceptionCaughtDialog.ShowStackTrace(ExceptionInfo ex)
at MonoDevelop.Debugger.ExceptionCaughtDialog.ExceptionValueSelectionChanged(Object sender, EventArgs e)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at GLib.Signal.ClosureInvokedCB(Object o, ClosureInvokedArgs args)
at GLib.SignalClosure.Invoke(ClosureInvokedArgs args)
at GLib.SignalClosure.MarshalCallback(IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data)
Pictures (a) & (b) show the errors
What I expect is the redirection to the host (yandex.ru in my case) with the "code"-variable in the url like:
GET http://www.yandex.ru/?code=47b313a9a77d259c7416c6f10b6f542210c7c78a6989ff2f394c2c67e3a67230f370857da16767144be7e76554fc6406bdbc37148653342620fc928e697eaa04c247cb23c546358d3109364fecc94bea0f665f15f7f2ad44ec6d63b348effce062b851595ff2fbe2fa9a77eeb3bd39dc91d80823daa506b3f6362623b306ad HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: www.yandex.ru
Header presented above is what I get under Windows Console App in Xamarin. So I did run the same code from the Xamarin Studio using simple Console Application .NET 4.5 under windows platform and get response just fine. I sniffed the HTTP Requests from the .NET 4.5 and mono-android library via Fiddler proxy, and both requests appeared with the same headers. In mobile case I get 465 bytes of response with charset=iso-8859-1 and 0 (red line) with expected charset=UTF-8 (I guess). In the case under windows I get 465b with charset=iso-8859-1 and after that 176 kb response with charset=UTF-8.
Pictures (c) and (d) show fiddler information. (c) mobile failed redirection, (d) windows successful redirection
Additional information:
- Xamarin Studio 4.2.3 (b60), Windows 7
- Tried to reinstall Xamarin Studio and all the componets clearing out the related AppData folders. Also, I reinstalled OS
- Tried to re-create app,including all the files from previous project while having default starting settings
- FastDev is checked off
- I have System.Net.ServicePointManager.Expect100Continue = false; If I delete this, there will be 417 error.
Also, instead of
response = httpClient.PostAsync( GetDecisionUrl(), contentDecision).Result;
I created async method:
async Task<HttpResponseMessage> PostDecision (HttpContent contentDecision)
{
Task<HttpResponseMessage> decisionTask = httpClient.PostAsync (GetDecisionUrl (), contentDecision); // async method!
HttpResponseMessage resp = await decisionTask;
Console.WriteLine (resp.Content);
return resp;
}
And tried to use it:
Task<HttpResponseMessage> asyncFunc = PostDecision (contentDecision);
response = asyncFunc.Result;
But application hangs, showing no exception, and fiddler shows the same case with 0 bytes (picture c.).
P.S. I can attach full code list (or my simple demo project) and fiddler debug information if it needs to.