{"action":"created","issue":{"url":"https://api.github.com/repos/twilio/twilio-csharp/issues/148","labels_url":"https://api.github.com/repos/twilio/twilio-csharp/issues/148/labels{/name}","comments_url":"https://api.github.com/repos/twilio/twilio-csharp/issues/148/comments","events_url":"https://api.github.com/repos/twilio/twilio-csharp/issues/148/events","html_url":"https://github.com/twilio/twilio-csharp/issues/148","id":52170562,"number":148,"title":"Catching Twilio Async Send SMS message Errors When host not available","user":{"login":"mwaarna","id":8648563,"avatar_url":"https://avatars.githubusercontent.com/u/8648563?v=3","gravatar_id":"","url":"https://api.github.com/users/mwaarna","html_url":"https://github.com/mwaarna","followers_url":"https://api.github.com/users/mwaarna/followers","following_url":"https://api.github.com/users/mwaarna/following{/other_user}","gists_url":"https://api.github.com/users/mwaarna/gists{/gist_id}","starred_url":"https://api.github.com/users/mwaarna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mwaarna/subscriptions","organizations_url":"https://api.github.com/users/mwaarna/orgs","repos_url":"https://api.github.com/users/mwaarna/repos","events_url":"https://api.github.com/users/mwaarna/events{/privacy}","received_events_url":"https://api.github.com/users/mwaarna/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-12-16T21:37:48Z","updated_at":"2015-01-05T23:43:51Z","closed_at":null,"body":"Our work environment is behind a firewall and we create rules for the IP addresses for API.Twilio.com.\r\n\r\nI am using the Async call to send SMS's, but when the IP address  changes or is unreachable , the async call throws an unhandled exception.\r\n\r\nQuestion: How can I catch the unhandled exception without it crashing the application?\r\n\r\nHow to Reproduce issue.\r\n1) Modify Host file to simulate IP Change(blocked access)\r\n127.0.0.1 api.twilio.com\r\n127.0.0.1 twilio.com\r\n2) Send Async SMS\r\ntry\r\n                {\r\nvar twilio = new TwilioRestClient(Twilio_AccountSid, Twilio_AuthToken);\r\n\r\n                    twilio.SendMessage(from, to, body, SMSProcessor.Properties.Settings.Default.Twilio_StatusCallBackURL, m =>\r\n                    {\r\n                        MessageHandling.TwilioAsyncCallBack(m, sms); // Asynch Call Back\r\n                    });\r\n}\r\n                catch (Exception ex)\r\n                {\r\n                    Logger.ReportError(\"SendSMS\", ex.ToString());\r\n                }\r\n\r\n\r\nError Result:\r\nSystem.NullReferenceException was unhandled\r\n  HResult=-2147467261\r\n  Message=Object reference not set to an instance of an object.\r\n  Source=Twilio.Api\r\n  StackTrace:\r\n       at Twilio.TwilioRestClient.<>c__DisplayClass95`1.<ExecuteAsync>b__94(IRestResponse`1 response) in C:\\Users\\demo\\Documents\\GitHub\\twilio-csharp\\src\\Twilio.Api.Silverlight\\Core.Async.cs:line 41\r\n       at RestSharp.RestClientExtensions.<>c__DisplayClass4`1.<ExecuteAsync>b__3(IRestResponse`1 response, RestRequestAsyncHandle asyncHandle)\r\n       at RestSharp.RestClient.DeserializeResponse[T](IRestRequest request, Action`2 callback, IRestResponse response, RestRequestAsyncHandle asyncHandle)\r\n       at RestSharp.RestClient.<>c__DisplayClassa`1.<ExecuteAsync>b__9(IRestResponse response, RestRequestAsyncHandle asyncHandle)\r\n       at RestSharp.RestClient.ProcessResponse(IRestRequest request, HttpResponse httpResponse, RestRequestAsyncHandle asyncHandle, Action`2 callback)\r\n       at RestSharp.RestClient.<>c__DisplayClass3.<ExecuteAsync>b__0(HttpResponse r)\r\n       at RestSharp.Http.ExecuteCallback(HttpResponse response, Action`1 callback)\r\n       at RestSharp.Http.RequestStreamCallback(IAsyncResult result, Action`1 callback)\r\n       at RestSharp.Http.<>c__DisplayClassa.<WriteRequestBodyAsync>b__6(IAsyncResult result)\r\n       at System.Net.LazyAsyncResult.Complete(IntPtr userToken)\r\n       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)\r\n       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)\r\n       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n       at System.Net.ContextAwareResult.Complete(IntPtr userToken)\r\n       at System.Net.HttpWebRequest.SetResponse(Exception E)\r\n       at System.Net.ConnectStream.ProcessWriteCallDone(ConnectionReturnResult returnResult)\r\n       at System.Net.ConnectStream.CallDone(ConnectionReturnResult returnResult)\r\n       at System.Net.ConnectStream.IOError(Exception exception, Boolean willThrow)\r\n       at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)\r\n       at System.Net.LazyAsyncResult.Complete(IntPtr userToken)\r\n       at System.Net.TlsStream.ResumeIOWorker(Object result)\r\n       at System.Net.TlsStream.WakeupPendingIO(IAsyncResult ar)\r\n       at System.Net.LazyAsyncResult.Complete(IntPtr userToken)\r\n       at System.Net.Security.SslState.FinishHandshake(Exception e, AsyncProtocolRequest asyncRequest)\r\n       at System.Net.Security.SslState.WriteCallback(IAsyncResult transportResult)\r\n       at System.Net.LazyAsyncResult.Complete(IntPtr userToken)\r\n       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)\r\n       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)\r\n       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n       at System.Net.ContextAwareResult.Complete(IntPtr userToken)\r\n       at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)\r\n       at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)\r\n  InnerException: \r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/twilio/twilio-csharp/issues/comments/68802982","html_url":"https://github.com/twilio/twilio-csharp/issues/148#issuecomment-68802982","issue_url":"https://api.github.com/repos/twilio/twilio-csharp/issues/148","id":68802982,"user":{"login":"mwaarna","id":8648563,"avatar_url":"https://avatars.githubusercontent.com/u/8648563?v=3","gravatar_id":"","url":"https://api.github.com/users/mwaarna","html_url":"https://github.com/mwaarna","followers_url":"https://api.github.com/users/mwaarna/followers","following_url":"https://api.github.com/users/mwaarna/following{/other_user}","gists_url":"https://api.github.com/users/mwaarna/gists{/gist_id}","starred_url":"https://api.github.com/users/mwaarna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mwaarna/subscriptions","organizations_url":"https://api.github.com/users/mwaarna/orgs","repos_url":"https://api.github.com/users/mwaarna/repos","events_url":"https://api.github.com/users/mwaarna/events{/privacy}","received_events_url":"https://api.github.com/users/mwaarna/received_events","type":"User","site_admin":false},"created_at":"2015-01-05T23:43:51Z","updated_at":"2015-01-05T23:43:51Z","body":"Small Update..\r\n\r\nUsing AppDomain.UnhandledException Event:\r\nhttp://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx\r\n\r\nI am able to catch the Async error, log and report on it, but the application still crashes the service when the host is not available.\r\n\r\nAny suggestions?"}}