I have a razor layout file that calls the partial view _MallCommonScripts.cshtml,
I setup the ScriptRegistrar as following:
And I get the exception "Cannot write to a closed TextWriter".
[ObjectDisposedException: Cannot write to a closed TextWriter.]
System.IO.StringWriter.Write(Char[] buffer, Int32 index, Int32 count) +14301681
System.IO.TextWriter.WriteLine(String value) +204
Telerik.Web.Mvc.UI.ScriptRegistrar.WriteScriptSources(TextWriter writer) +172
Telerik.Web.Mvc.UI.ScriptRegistrar.Write(TextWriter writer) +31
Telerik.Web.Mvc.UI.ScriptRegistrar.Render() +104
ASP._Page_Views_Shared__MallCommonScripts_cshtml.Execute() in d:\Projects\EMall\devel\solution\src\Halcyon.Mall.Web\Views\Shared\_MallCommonScripts.cshtml:18
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +196
System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +147
ASP._Page_Views_Shared__DbdLayout_cshtml.Execute() in d:\Projects\EMall\devel\solution\src\Halcyon.Mall.Web\Views\Shared\_DbdLayout.cshtml:37
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +196
System.Web.WebPages.WebPageBase.Write(HelperResult result) +89
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +233
System.Web.WebPages.WebPageBase.PopContext() +291
System.Web.WebPages.WebPageBase.Write(HelperResult result) +89
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +233
System.Web.WebPages.WebPageBase.PopContext() +291
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +380
System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +33
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +613
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +263
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +240
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
The exception is thrown on SOME pages ONLY, which I cannot tell the differences between the pages that throws or not.
The workaround is to change the last line of the ScriptRegistrar setup code from scripts.Render() to "@script":
Wish this helps.