Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does EndGetResponse throw ArgumentNullException?

The following line of code throws an ArgumentNullException under Chrome and Firefox in silverlight. I am using HttpWebRequest to post a file to the server. The exception doesn't happen in IE and only happens when I am uploading a larger file (5mb). Under IE it works just fine. I didn't see any reason in the documentation why the code would throw this exception.

//note that asyncResult is not null
response = (HttpWebResponse)request.EndGetResponse(asyncResult);

Here is the stack trace from the exception:

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)

and inner exception:

at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at DC.FileUpload.FileUpload.<>c__DisplayClassc.<UploadFileEx>b__a(IAsyncResult asyncResult)
like image 850
NotDan Avatar asked Nov 05 '22 10:11

NotDan


2 Answers

I got exactly same weird error with HttpWebResponse (but in absolutely other circumstances) few days ago. In my case it was multithreading problem. Looks like main thread and one of working threads (with delegate) tries to share some variable. So I may suggest you try to move all class level variables into methods bodies (or add locking for critical sections) and then debug your application with active "Threads" window.
To enable this window click Debug=>Windows=>Threads during debugging. I hope it helps you in struggle with that weird error.

like image 152
Igor V Savchenko Avatar answered Nov 14 '22 21:11

Igor V Savchenko


I get this exception any time I can't reach the server to make the request. That might be understandable, but I also see this error for any long-running requests, even when I can reach the server. Requests that take longer than 10 seconds consistently cause the client to fail with this exception.

It might have something to do with the environment in which Silverlight is running. You state that in IE, the error doesn't occur, but it does in Firefox and Chrome. My application is running out-of-browser. From this I can only assume that the client stack still leverages IE in some way if it is running in IE.

like image 37
slipjig Avatar answered Nov 14 '22 21:11

slipjig