2009-02-19 23 views
1

我看到下面的异常。未将对象引用设置为对象的实例

System.NullReferenceException:未将对象引用设置为对象的实例。 at System.Web.Util.StringUtil.memcpyimpl(Byte * src,Byte * dest,Int32 len) at System.Web.Util.StringUtil.UnsafeStringCopy(String src,Int32 srcIndex,Char [] dest,Int32 destIndex,Int32 LEN) 在System.Web.HttpWriter.Write(字符串或多个) 在System.Web.HttpResponse.Write(字符串或多个)

我已经在上下文以下检查到我响应。

return !(context == null || context.Response == null || 
    context.Response.OutputStream == null || 
    !context.Response.OutputStream.CanWrite); 

任何人都可以提示什么可能会导致此?

回答

0

为什么还要打扰所有这些检查?为什么不直接写出输出流并使用它呢?

此外,ASP.NET处理管道中的哪个位置正在进行此调用?

+0

//获取文本书写器的本地副本 \t \t \t TextWriter writer = context.Response.Output; \t \t \t \t \t \t //写出消息映射 \t \t \t writer.Write( “输出数据...”); – user68575 2009-02-19 19:40:21

1

你确定这是错误的地方吗?看起来像是从HttpResponse的Write方法开始的异常。

0

,我认为你的错误是在其他地方,但我建议写这个表情多了几分的情况下直接底片:

return context != null && context.Response != null && 
    context.Response.OutputStream != null && 
    context.Response.OutputStream.CanWrite; 
0

这可能,如果你想真正写一个空对象到是发生缓冲IE:

context.Response.OutputStream.Write(null, 0, 0); 

你也可以把它表示...

return (context != null && context.Response != null && 
    context.Response.OutputStream != null && 
    context.Response.OutputStream.CanWrite); 
1

我在使用异步处理程序和模块时发生此错误。我的问题是我会使用HttpHandler's EndProcessRequest方法中的ThreadPool.QueueUserWorkItem,并在工作项回调中尝试使用HttpContext。问题是一旦EndProcessRequest返回给调用者(但工作项回调尚未调用),HttpContext对象实例不再是“我的”,并且ASP.NET已经采取了控制并正在将其拆除。有关更多信息,请参见http://odetocode.com/articles/112.aspx

相关问题