开发者

Why is Output Stream not available when a custom TextWriter is used, after upgrading project to VS 2010?

I upgraded a project I did in Visual Studio 2008 to VS 2010 an开发者_JS百科d now the following line won't compile

using (TextWriter textWriter = new StreamWriter(_viewContext.HttpContext.Response.OutputStream))
{
    textWriter.Write(_tag.ToString(TagRenderMode.EndTag));
}

The error message I'm getting is:

OutputStream is not available when a custom TextWriter is used.

Can anyone fill me in on what I need to do? Thanks

Edit: the target framework is .Net 3.5


If you have the option of changing the code, try this instead:

using (StreamWriter sw = new StreamWriter(_viewContext.HttpContext.Response.OutputStream))
{
    using (TextWriter textWriter = TextWriter.Synchronized(sw))
    {
        textWriter.Write(_tag.ToString(TagRenderMode.EndTag));
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜