title: Why does my custom HttpResponse throw exception on HttpResponse.End()?
body: <p>I'm writing some code in which I need to use my own <code>HttpResponse</code> object to capture the output from a method on another object that takes an <code>HttpResponse</code> as a parameter.  The problem is, this other object (which I cannot modify) calls <code>HttpResponse.End()</code>, which causes an "Object reference not set to an instance of an object" exception to be thrown.  What can I do about this?</p>
  
  <pre><code>Dim myStringbuilder As New StringBuilder
  Dim myStringWriter As New IO.StringWriter(myStringbuilder)
  Dim myResponse As New Web.HttpResponse(myStringWriter)
  
  someObject.doStuffWithHttpResponse(myResponse) ' calls myResponse.End() and crashes
  </code></pre>
  
  <p>Here's some more complete information about the error, thrown from the following code in a console application:</p>
  
  <pre><code>Dim myStringbuilder As New StringBuilder
  Dim myStringWriter As New IO.StringWriter(myStringbuilder)
  Dim myResponse As New Web.HttpResponse(myStringWriter)
  Try
   myResponse.End()
  Catch ex As Exception
   Console.WriteLine(ex.ToString)
  End Try
  </code></pre>
  
  <p>Here's the text of the exception:</p>
  
  <blockquote>
    <p>System.NullReferenceException: Object reference not set to an instance of an object.
       at System.Web.HttpResponse.End()
       at ConsoleApplication1.Module1.Main() in C:\Documents and Settings\joe.user\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Module1.vb:line 10</p>
  </blockquote>