Unhandled exception

Dec 2, 2013 at 9:28 AM
Edited Dec 2, 2013 at 12:03 PM
I use LinqToTwitter in my project.
Sometimes, I receive unhandled exception and application shutdown.
I caught this exception using AppDomain.CurrentDomain.UnhandledException.

System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult)
at LinqToTwitter.ApplicationOnlyAuthorizer.<>c__DisplayClassd.<GetBearerToken>b__7(IAsyncResult ar)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.HttpWebRequest.SetResponse(Exception E)
at System.Net.ConnectionReturnResult.SetResponses(ConnectionReturnResult returnResult)
at System.Net.Connection.CompleteConnectionWrapper(Object request, Object state)
at System.Net.PooledStream.ConnectionCallback(Object owningObject, Exception e, Socket socket, IPAddress address)
at System.Net.ServicePoint.ConnectSocketCallback(IAsyncResult asyncResult)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

Can you help me with this problem?
Dec 2, 2013 at 10:27 AM
Edited Dec 2, 2013 at 11:09 AM
Sorry, find this discussion (https://linqtotwitter.codeplex.com/discussions/393527), it's the same problem. But problem has still actual for me.
Dec 2, 2013 at 3:41 PM

Which LINQ to Twitter query were you using?

@JoeMayo on Twitter
Dec 3, 2013 at 7:13 AM
I find user by userName with specified hashtags. I use something like this:
statuses = context.Status
                .Where(x =>
                             x.Count == 50 &&
                             x.Type == StatusType.User &&
                             x.User.Identifier.ScreenName == userName &&
                             hashTagList.All(t => x.Entities.HashTagEntities.Select(h => h.Tag).Contains(t))
                ).OrderBy(x => x.StatusID).ToList();
Then save it to custom list.
I run this query every minute, it work fine, but sometimes I receive unhandled exception about one time in twenty-four hours.
Dec 4, 2013 at 6:31 PM
Do you wrap the code in a try/catch block. I tried to reproduce, but the exception is always caught in my catch block. Are you using the latest version of LINQ to Twitter?

BTW, I reproduced by disconnecting my network connection.

@JoeMayo on Twitter
Dec 5, 2013 at 7:49 AM
Yes, I have wrapped code in try/catch block. Use the latest version of LINQ to Twitter. I'm tried to disconnect network connection by hand and I also caught the exception by try/catch. I don't know why the unhandled exception occur. I use windows service, I set restart service in case error, it works, but hope the exception will determine and resolved.