简体   繁体   English

将项目升级到 VS 2010 后,为什么使用自定义 TextWriter 时输出流不可用?

[英]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 and now the following line won't compile我将我在 Visual Studio 2008 中所做的项目升级到 VS 2010,现在以下行将无法编译

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编辑:目标框架是 .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));
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用自定义TextWriter时,OutputStream不可用 - OutputStream is not available when a custom TextWriter is used 使用mvc自定义TextWriter时,OutputStream不可用 - OutputStream is not available when a custom TextWriter is used mvc 具有自定义actionresult的ASP.NET MVC:使用自定义TextWriter时outputStream不可用 - ASP.NET MVC with custom actionresult: outputStream is not available when a custom TextWriter is used 在ASP .NET中将图像写入响应中将导致“使用自定义TextWriter时,OutputStream不可用。” - Writing image to response in ASP .NET results in “OutputStream is not available when a custom TextWriter is used.” 将VS2008 / .NET FX 2.0项目升级到VS2010后出现奇怪的错误 - Getting a weird error after upgrading a VS2008/.NET FX 2.0 project to VS2010 使用TextWriter时如何截断流 - How to truncate a stream when using a TextWriter 将文本流输出到VS2010输出窗口 - Output stream of text to VS2010 Output Window 自将项目转换为VS2010后,HttpListenerRequest属性不再可用 - HttpListenerRequest properties no longer available since converting project to VS2010 使用命令行构建VS安装项目时为什么没有输出? - why no output when use command line to build VS setup project? 在项目开发过程中从VS2010升级到VS2012会有任何风险吗? - Is there any risk in upgrading from VS2010 to VS2012 in the middle of project development?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM