What causes the System.Web.HttpException with error code 0x80070057 on Page.Flush while debugging in VS2005?

21,164

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!

Share:
21,164
Ishmael
Author by

Ishmael

I currently work in Visual Studio with C# and SQL Server. I am quite intimate with XML, XSLT and their various allies. Client side, I have hacked tons of JavaScript, HTML, CSS and so on.

Updated on July 09, 2022

Comments

  • Ishmael
    Ishmael almost 2 years

    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).

  • Brian
    Brian about 14 years
    I suspect #2 is a race condition, since the client may disconnect after you check IsClientConnected.