c# - WebException thrown in WinRT app that cannot be caught -
this issue bizarre , has eluded attempts @ debugging. occurs when running app on surface tablet. not occur on asus tablet or while running in visual studio. in particular scenario airplane mode has been turned on, webexception thrown absolutely unable catch. i'm not entirely in code causing happen, because of logging not happening after point in code unknown reason. can assume it's caused httpwebrequest, because of type of exception being thrown, appears coming internal .net component. here debugging information i'm able obtain. it's windows event viewer:
application: <myappname.exe> framework version: v4.0.30319 description: process terminated due unhandled exception. exception info: system.net.webexception stack: @ system.net.servicepoint.connectsocketcallback(system.iasyncresult) @ system.net.lazyasyncresult.complete(intptr) @ system.net.contextawareresult.complete(intptr) @ system.net.lazyasyncresult.protectedinvokecallback(system.object, intptr) @ system.net.sockets.socket.connectcallback() @ system.net.sockets.socket.registeredwaitcallback(system.object, boolean) @ system.threading._threadpoolwaitortimercallback.performwaitortimercallback(system.object, boolean)
i wish had more debugging information provide, i've tried can think of tons of try/catch blocks everywhere , logging after calls--some of isn't executed. have clue causing this?
edit 1:
based on traces exception appears thrown somewhere in here. virtually wrapped in try/catch block, can't see how webexception possibly slipping through.
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) => { using (stream uploadstream = request.endgetrequeststream(rasyncresult)) { try { uploadstream.write(bytes, 0, bytes.length); uploadstream.flush(); } catch (exception e) { // exception handling } { uploadstream.dispose(); } } iasyncresult responseresult = (iasyncresult)request.begingetresponse((resasyncresult) => { try { using (httpwebresponse response = (httpwebresponse)request.endgetresponse(resasyncresult)) { try { data = processresponse(xmlreader.create(response.getresponsestream())); } catch (exception e) { // exception handling } { response.dispose(); } } } catch (webexception e) { // exception handling } }, null); }, null); } catch (exception e) { // exception handling }
edit 2:
i still have not found acceptable solution. i'm checking connection type before-hand , not allowing code continue if it's not connected wifi, mobile, or ethernet, doesn't catch condition it's connected network has no internet connection. winrt has no solution check internet connectivity, , method i'm using unfriendly work (it passes number--http://social.msdn.microsoft.com/forums/en-us/winappswithcsharp/thread/d8e76732-19d3-47b3-840f-70d87c75ce9f).
did try handling application.unhandledexception
?
add event handler event in app
class constructor:
public app() { // keep rest of constructor this.unhandledexception += onunhandledexception; }
in event handler can log exception , mark handled prevent app closing / crashing:
void onunhandledexception(object sender, unhandledexceptioneventargs e) { // log e.exception details investigation e.handled = true; }
Comments
Post a Comment