我正在编写一些代码,其中我需要使用我自己的HttpResponse
对象来捕获另一个对象上的方法的输出,该对象以 anHttpResponse
作为参数。问题是,这个其他对象(我无法修改)调用HttpResponse.End()
,这会导致“对象引用未设置为对象的实例”异常被抛出。我能做些什么呢?
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
以下是有关错误的更完整信息,从控制台应用程序中的以下代码抛出:
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
这是异常的文本:
System.NullReferenceException:对象引用未设置为对象的实例。在 System.Web.HttpResponse.End() 在 ConsoleApplication1.Module1.Main() 在 C:\Documents and Settings\joe.user\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Module1.vb:line 10