views:

1565

answers:

1

Here is the complete error message:

An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code

Additional information: The remote host closed the connection. The error code is 0x80070057.

and the offending code:

 char[] buffer = oPage.HTML.HTML.ToCharArray();
 Page.Response.Write(buffer, 0, buffer.Length);
 Page.Response.Flush();
 Page.Response.End();

The oPage.HTML.HTML is a string in a custom page object used by our app. The exception triggers on Page.Flush() and appears to be benign -- I just hit "continue" and everything goes along fine. This never appears at run time.

I have chased many, many Google hits down many rabbit holes and have found nothing. Visual Studio 2005, Vista Ultimate (IIS7).

+4  A: 

I've been dealing with this same error for a while now, and my understanding is that when Flush is called, there must be a connection on the other end, otherwise, this error is thrown. It's easy to get into a "fire-and-forget" kind of model when writing web pages, but when the client disconnects (in this debugging case, you're the client), there's nowhere to flush to.

There are two solutions I've found to this:

  1. Wrap Response.Flush and catch the exception.
  2. Check Response.IsClientConnected before you call flush.

I'm not 100% sure about the second one...I'm still in the process of checking that one out.

Good luck!

Chris B. Behrens
I suspect #2 is a race condition, since the client may disconnect after you check IsClientConnected.
Brian