Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > General Discussions > Style Sheet Registrar giving: "Cannot write to a closed TextWriter. " when it is inside of a partial view or template
Telerik MVC Extensions are no longer supported (see this page for reference). In case you have inquiries about Kendo UI Complete for ASP.NET MVC, post them in the pertinent Kendo UI forums.

Not answered Style Sheet Registrar giving: "Cannot write to a closed TextWriter. " when it is inside of a partial view or template

Feed from this thread
  • Mike avatar

    Posted on Oct 31, 2011 (permalink)

    I am getting "Cannot write to a closed TextWriter. " when it is inside of a partial view or template. I just upgraded to the latest Telerik package and started getting this on code that was there prior. If I take the same stuff and put it directly in the head of the Master Page, then it works. I like to keep the stylesheet registrar in its own control due to some of the site's complexities.

    Thanks,
    Mike

  • Mike avatar

    Posted on Nov 17, 2011 (permalink)

    Hey Telerik, is there anyone out there? It seems like I have posted quite a few times on this site and not one has been answered by you guys. Pretty sad since I am a proponent of your tools and I usually put them in my client's solutions. Would be nice if you guys answered every once in a while. Thanks.

    Mike

  • Georgi Tunev Georgi Tunev admin's avatar

    Posted on Nov 18, 2011 (permalink)

    Hi Mike,

    The forums are a community resource and although we monitor them, we don't guarantee a timely response here. If you need a faster reply, you should use the support ticketing system. It assigns response time (according to the purchased license) to every issue that is submitted and forwards it to the corresponding teams.

    As for the problem itself, if you still experience it, please provide a sample project so we can investigate further. We will check it and get back to you right away.

    All the best,
    Georgi Tunev
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now

  • Posted on Oct 3, 2012 (permalink)

    I have a razor layout file that calls the partial view _MallCommonScripts.cshtml, 
    I setup the ScriptRegistrar as following:

        var scripts = Html.Telerik().ScriptRegistrar()
            .Globalization(true)
            .jQuery(false).jQueryValidation(false) //disable the jQuery shipped with Telerik, which is of version 1.7.1
            .CombinedComponentFile(true)
            .DefaultGroup(
                g =>
                {
                    g.Add("~/Scripts/jquery-1.8.2.min.js");
                    g.Add("~/Scripts/jquery.validate.min.js");
                    g.Add("~/Scripts/jquery.validate.unobtrusive.min.js");
     
                    g.Combined(true);
                    g.Compress(false);
                });
        scripts.Render(); //will cause "Cannot write to a closed TextWriter" exception
    }


    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":

    //scripts.Render(); //will cause "Cannot write to a closed TextWriter" exception on SOME pages
    @scripts    //This works for all pages

    Wish this helps.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > General Discussions > Style Sheet Registrar giving: "Cannot write to a closed TextWriter. " when it is inside of a partial view or template