Note that there are some explanatory texts on larger screens.

plurals
  1. POWebException thrown in WinRT app that cannot be caught
    primarykey
    data
    text
    <p>This issue is really bizarre and has eluded my attempts at debugging. It only occurs when running the app on a Surface tablet. It does not occur on an Asus tablet or while running in Visual Studio. In a particular scenario where Airplane mode has been turned on, a WebException is thrown that I am absolutely unable to catch. I'm not even entirely certain what in my code is causing it to happen, because some of my logging is not happening after a certain point in the code for an unknown reason. I can only assume it's caused by an HttpWebRequest, because of the type of exception being thrown, which appears to be coming from an internal .NET component. Here is the only debugging information I'm able to obtain. It's from the Windows Event Viewer:</p> <pre><code>Application: &lt;myappname.exe&gt; Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.Net.WebException Stack: at System.Net.ServicePoint.ConnectSocketCallback(System.IAsyncResult) at System.Net.LazyAsyncResult.Complete(IntPtr) at System.Net.ContextAwareResult.Complete(IntPtr) at System.Net.LazyAsyncResult.ProtectedInvokeCallback(System.Object, IntPtr) at System.Net.Sockets.Socket.ConnectCallback() at System.Net.Sockets.Socket.RegisteredWaitCallback(System.Object, Boolean) at System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(System.Object, Boolean) </code></pre> <p>I really wish I had more debugging information to provide, but I've tried everything I can think of with tons of try/catch blocks everywhere and logging after most calls--some of which isn't be executed. Does anyone have any clue as to what could be causing this?</p> <p>EDIT 1:</p> <p>Based on traces the exception appears to be thrown somewhere in here. Virtually everything is wrapped in a try/catch block, so I can't see how the WebException could possibly be slipping through.</p> <pre><code>byte[] bytes = Encoding.UTF8.GetBytes(requestXml.ToString()); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "POST"; request.ContentType = "text/xml"; try { IAsyncResult requestResult = (IAsyncResult)request.BeginGetRequestStream((rAsyncResult) =&gt; { using (Stream uploadStream = request.EndGetRequestStream(rAsyncResult)) { try { uploadStream.Write(bytes, 0, bytes.Length); uploadStream.Flush(); } catch (Exception e) { // Exception handling } finally { uploadStream.Dispose(); } } IAsyncResult responseResult = (IAsyncResult)request.BeginGetResponse((resAsyncResult) =&gt; { try { using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(resAsyncResult)) { try { data = ProcessResponse(XmlReader.Create(response.GetResponseStream())); } catch (Exception e) { // Exception handling } finally { response.Dispose(); } } } catch (WebException e) { // Exception handling } }, null); }, null); } catch (Exception e) { // Exception handling } </code></pre> <p>EDIT 2:</p> <p>I still have not found an acceptable solution. I'm currently checking the connection type before-hand and not allowing the code to continue if it's not connected to WiFi, Mobile, or Ethernet, but that doesn't catch the condition where it's connected to a network that has no Internet connection. WinRT has no solution to check Internet connectivity, and even the method I'm using is unfriendly to work with (it just passes back a number--<a href="http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/d8e76732-19d3-47b3-840f-70d87c75ce9f" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/d8e76732-19d3-47b3-840f-70d87c75ce9f</a>).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload