I recently updated my client sdk to parse 1.6.2 for xamarin, and I noticed that ParseExceptions are no longer getting thrown properly.
When calling something like this:
string result = await ParseCloud.CallFunctionAsync<string>( "function" )
If that function calls response.error I get:
System.Net.WebException The remote server returned an error: (400) Bad Request.
Raw
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in /Users/builder/data/lanes/2377/73229919/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:944
Where as in the pass it would generate a ParseException with the contents of the response.error. The WebException also does not have an inner exception to inspect.
I also thought it had something to do with my cloud code, but I find a similar problem with user login. A bad password generates this exception now:
System.Net.WebException The remote server returned an error: (404) Not Found.
Raw
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in /Users/builder/data/lanes/2377/73229919/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:944
A few other things were upgraded when I updated the parse sdk. I'm now using xamarin forms 2.* instead of 1.5.* and I think the mono system libraries were also updated.
Related
In my application, there is a functionality to extract reports based on a date range. In the background, it is calling my Web API with authentication(A), which consists of api caller functionality using httpclient, which is calling another non-secured DMZ server API (B) and a DMZ API-caliing WCF service (C) to collect data from the database.
My problem is that whenever I select a large date range, I get the following error in my WebAPI (A).
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly.
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at LRAS.OrderServices.Core.Helpers.ApiCaller.d__4.MoveNext()
What I have tried: I have increased the httpclient timeout from 300 to 1000 seconds, but it is breaking nearly every minute.
You can try several methods:
1.Configure the service point security protocol and select the SecurityProtocolType that suits you (Tls12, Ssl3, Tls, Tls11).
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
C# System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send
2.Set the ConnectionClose property of HttpClient.
_client.DefaultRequestHeaders.ConnectionClose = true;
HttpClient throwing "An error occurred while sending the request."
3.Try to hold the request long enough for it to complete normally and receive a valid response.
_client.DefaultRequestHeaders.Add("Connection", "Keep-Alive");
_client.DefaultRequestHeaders.Add("Keep-Alive", "3600");
.NET HttpClient - An existing connection was forcibly closed by the remote host
I'm using the following code to get calendar appointments from my Office 365 account with EWS api's set (Microsoft.Exchange.WebServices 2.2.0):
ExchangeService service = new ExchangeService();
service.Credentials = new NetworkCredential(mail, password);
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
Folder DefaultCalendar = Folder.Bind(service, WellKnownFolderName.Calendar);
CalendarView calendarView = new CalendarView(fromDate, toDate);
FindItemsResults<Appointment> resultAppointments = Folder.FindAppointments(calendarView);
often the application crash with the following exceptions:
Microsoft.Exchange.WebServices.Data.ServiceRequestException: The
request failed. The operation has timed out --->
System.Net.WebException: The operation has timed out at
System.Net.HttpWebRequest.GetResponse() at
Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse()
at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest
request) --- End of inner exception stack trace --- at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest
request) at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest&
request) at
Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
at
Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder(FolderId
folderId, PropertySet propertySet) at
Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder[TFolder](FolderId
folderId, PropertySet propertySet) at
Microsoft.Exchange.WebServices.Data.CalendarFolder.Bind(ExchangeService
service, FolderId id)
or:
Microsoft.Exchange.WebServices.Data.ServiceRequestException: The
request failed. The remote server returned an error: (503) Server
Unavailable. ---> System.Net.WebException: The remote server returned
an error: (503) Server Unavailable. at
System.Net.HttpWebRequest.GetResponse() at
Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse()
at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest
request) --- End of inner exception stack trace --- at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest
request) at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest&
request) at
Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
at
Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder(FolderId
folderId, PropertySet propertySet) at
Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder[TFolder](FolderId
folderId, PropertySet propertySet) at
Microsoft.Exchange.WebServices.Data.CalendarFolder.Bind(ExchangeService
service, FolderId id)
or:
Microsoft.Exchange.WebServices.Data.ServiceRequestException: The
request failed. The underlying connection was closed: A connection
that was expected to be kept alive was closed by the server. --->
System.Net.WebException: The underlying connection was closed: A
connection that was expected to be kept alive was closed by the
server. at System.Net.HttpWebRequest.GetResponse() at
Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse()
at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest
request) --- End of inner exception stack trace --- at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest
request) at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest&
request) at
Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest1.Execute()
at
Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems[TItem](IEnumerable1
parentFolderIds, SearchFilter searchFilter, String queryString,
ViewBase view, Grouping groupBy, ServiceErrorHandling
errorHandlingMode) at
Microsoft.Exchange.WebServices.Data.Folder.InternalFindItems[TItem](SearchFilter
searchFilter, ViewBase view, Grouping groupBy) at
Microsoft.Exchange.WebServices.Data.CalendarFolder.FindAppointments(CalendarView
view)
or:
The server cannot service this request right now. Try again later.
It seems that sometimes Office 365 services are unreachable or on throttling; I tried to try-catch my code, but the application still crash; I think because a new Thread is opened. How can I handle this issue?
The first place to start is to get the latest version of the EWS Managed API from Github https://github.com/OfficeDev/ews-managed-api . The version you using hasn't been update since 2015 which is when Microsoft stopped releasing compiled versions of that library. However the code has been updated with numerous bug fixes on GitHub
With the code your using I would suggest you always set the X-AnchorMailBox which can cause 503 and timeout issues see
https://blogs.msdn.microsoft.com/webdav_101/2015/05/11/best-practices-ews-authentication-and-access-issues/ (even if your not using Impersonation)
Depending on how much work your application is doing you may get throttled its important in that case to process the exception and retry. Also with Office365 mailboxes get moved around a fair bit on the back-end so it can be common to see period where the Mailbox is inaccessible during these moves
I tried to try-catch my code, but the application still crash; I think because a new Thread is opened. How can I handle this issue?
No it doesn't span a new thread you can check the source yourself on GitHub so you must have another issue with your exception handling.
I'm getting this exception when awaiting LoginAsync:
await fb.LoginAsync("user_about_me");
The full stack trace is the following:
{System.InvalidOperationException: Operation is not valid due to the current state of the object.
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at FacebookServiceClient.FbServiceClient.<Login>d__0.MoveNext()}
I'm using Facebook Client 0.5.0.
The strange thing is that this error doesn't always occur, usually when I start a coding session everything is just fine, but then (after a few debug sessions) this exception popups every time.
Any thoughts?
Edit: I have this problem even on the SDK github sample
The problem is not anything to do with the operation itself after browsing the code I found out that the problem is when the browser fails to connect to facebook this exception is thrown.
I have a .NET program running on Ubuntu via Mono 2.10
The program downloads a webpage via an HttpWebRequest every minute or so which works fine most of the time:
String result;
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
using (objResponse = objRequest.GetResponse())
{
using (StreamReader sr =
new StreamReader(objResponse.GetResponseStream()))
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
}
The problem is that after few days I start getting exceptions thrown:
DateTime: 01/25/2012 08:15:41
Type: System.Net.WebException
Error: Error: NameResolutionFailure
Stack:
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
at socks_server.Program.readHtmlPage (System.String url) [0x00000] in <filename unknown>:0
at socks_server.Program.getAccessKeysProc () [0x00000] in <filename unknown>:0
The server is still abel to resolve DNS, for example
wget http://www.google.com
Will return the file without any probelm as will ping and other commands that resolve DNS.
My program however will continue to throw that exception until I restart it. After restarting the application it will start working again as it should.
I have checked open file counts on the system (400 ish), memory usage (327mb of 4gb), CPU usage (2-3%) and all are OK.
Any ideas?
You can solve it by translating the host name to ip and add the host name to Headers collection or to Host property.
If your url is http://example.com/uri. Resolve the host yourself. Suppose its 1.2.3.4. It'll be http://1.2.3.4/uri. Now add Host: example.com header to your request. I think it can be done by setting HttpWebRequest.Host property.
I know this is an old post, but was facing the same error, so thought to share the solution.
The best solution I found, when that exception occurs while the Wifi
is connected, is just to retry my server call with a slight sleep in
between. It works most of the time, otherwise if the second call
fails I cancel the request.
This error can also raise if the user's Wifi is very unstable or the
signal is very low. The same error occurs if there is no internet
connection at all, even if connected to Wifi.
This is in line with my ans on :
System.Net.WebException: Error: NameResolutionFailure when Calling WCF Services throwing exception in mono android application
Well I use the HttpClient - but it might be a similar problem. I had the same issue on a Android device (it worked on a Windows Phone)... But after I added the Host to the header it worked!
client.DefaultRequestHeaders.Host = "mydomain.com";
You can still use the name in the url (you don't have to use the IP address)
I was experiencing the same issue in my mono application on raspbian. I've tried different solutions described in this and other threads but none worked. Eventually, I was able to fix the problem by changing the name servers in /etc/resolv.conf to the google ones https://developers.google.com/speed/public-dns/
Mirko
I was getting this error when I started the mobile app (android or iOS it does not matter) without internet connection. After restored the connection every request returns "NameResolutionFailure exception". I had to wait 120 seconds for having the http request working again. Setting the following line of code anywhere in the app startup the error was finally gone.
System.Net.ServicePointManager.DnsRefreshTimeout = 0;
The default DnsRefreshTimeout value is 120 seconds.
I'm using Silverlight 4.0, and am trying to get a request trough https. All I get is the exception below, which is not really helpful, because no search engine finds any related solution...
request = WebRequest.Create( new Uri("https://myurl.com/myfile" ) );
asyncResult = request.BeginGetResponse();
...
request.EndGetResponse( asyncResult );
{System.ArgumentNullException ---> System.ArgumentNullException: Value cannot be null.
Parameter name: s
at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
--- End of inner exception stack trace ---
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
It works when I use http instead of https. It works when I use the browser via https. But not like this. Any hints where to look for an answer, or even an answer would be very much appreciated.
[EDIT]
Ok, I found out what seems to be the problem: apparently it has something to do with Firefox and certificates. When I run the xap in IE, it asks me to trust a certificate, and then it works. In Firefox I never get such a question, and it never works (even though I downloaded the xap over that very address.) So now the question is: How do I get working https, Firefox and Silverlight to work together?
[EDIT2]
I'm still on the same problem, but there is something more to it. Not only Firefox has the problem, but also out-of-browser (even if installed from IE). There is someone with a similar exception, but no answer: http://forums.silverlight.net/forums/p/210114/494451.aspx
Got it.
The problem was that the Root CA Certificate of the Server was untrusted. Because I had IE 6 installed, I did not really see the message. The exception added to Firefox did not propagate to Silverlight (because Silverlight apparently always the Global Windows Certificates).
Installing IE 8 reveals that the Root CA Certificate was untrusted right beside the address bar. Click that message, add the Root CA Certificate to the ones used by Windows and voilĂ , everything works, IE, OOB and Firefox.