Null reference in HttpContext.OnReceive

Apr 26, 2010 at 3:39 PM

I just started using the project (39579, Apr 11) in Visual Studio an noticed that each time I the HTTP server handled a request, a NullReferenceException is thrown at line 143:

Stream.BeginRead(_buffer, 0, _buffer.Length - offset, OnReceive, null);

Looking at the code, it appears that Stream points to an object when the method begins, but is set to null by the time we get here.  The exception is caught, but with first-chance exception handling turned on in VS, I had to stop at that line each time.  I made a provisional change in my copy of the source to sidestep that by simply creating a local variable to point at whatever Stream is pointing to, guessing that Stream is being changed by code in another thread between when the method starts and when we get to line 143:

 

Stream localStream = this.Stream;
if(localStream != null)
    localStream.BeginRead(_buffer, 0, _buffer.Length - offset, OnReceive, null);


So far as I can tell, this didn't break anything.  But since I've only been in the code a little while and have a pretty thin understanding of it, I thought I would bring it to the attention of the developer.

Many thanks.

 

Coordinator
May 11, 2010 at 7:38 AM

I think that it have been fixed, try again with latest version.