1.8.1 - Cannot write to a closed TextWriter

Topics: General
Jun 23, 2014 at 6:44 PM
Edited Jun 23, 2014 at 6:46 PM

Hi everyone - I am updating a 1.7 site to the latest 1.8.X branch, and I am getting the following error on any of my module's pages:

2014-06-23 10:16:01,126 [95] Orchard.Exceptions.DefaultExceptionPolicy - Default - An unexpected exception was caught
http://www.atlstage.com/camp
System.ObjectDisposedException: Cannot write to a closed TextWriter.
at System.IO.StringWriter.Write(String value)
at Orchard.Mvc.ViewEngines.ThemeAwareness.LayoutAwareViewEngine.<>c__DisplayClass7.<FindView>b__5(ViewContext viewContext, TextWriter writer, IViewDataContainer viewDataContainer)
at Orchard.Mvc.ViewEngines.ThemeAwareness.LayoutAwareViewEngine.LayoutView.Render(ViewContext viewContext, TextWriter writer)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)

at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)

This is happening in LayoutAwareViewEngine.cs, FindView() method, line 64 (writer.Write()). This is a core area so I'm raising the issue here. Of course, it worked fine in 1.7 and even 1.8, so perhaps a bug has been introduced.

Any views I am rendering are coming from my own controllers with the [Themed] attribute applied. I also have the [AlwaysAccessible] attribute on my base controller, plus a custom filer that switches the protocol to https when users make requests from my module. Nothing too strange. Has anyone seen this before? Any thoughts?

Thanks.

Kurt Mang
Jun 23, 2014 at 6:54 PM
Quick update to this issue - I just reverted my source to the 1.8 (origin) master branch (checkin 9dcb790d) and everything works as expected.

FYI. Hope this is an easy one :-)

PS - don't know what's going on with the markup in the questions - it's not me doing that!

Kurt
Jul 2, 2014 at 8:10 AM
Edited Jul 2, 2014 at 8:12 AM
We've got the same issue so we cannot upgrade to 1.8.1 just yet. TheThemeMachine seems to be working fine but we've got custom themes. It works fine on localhost.

François
Jul 8, 2014 at 6:48 PM
I had the same stack trace and I think it's related to the changes in OutputCacheFilter.cs and how it caches the content when initially populating the cache. Try disabling the output cache module and see if the problem goes away, if so perhaps your solution will be the same as mine. I had a call to Html.RenderAction in one of my views which was throwing out the Response.Output (see code around line 295 - 299 of OutputCacheFilter.cs), removing my own call to Html.RenderAction solved this issue for me.
Jul 8, 2014 at 8:51 PM
Thanks for the reply! I will definitely look into this - I'd love to migrate to 1.8.1 but this issue has prevented that. I'll post the outcome here when I implement the fix.

Kurt