RadStylesheetManager not picking up registered stylesheets in custom controls

4 posts, 0 answers
  1. Ron
    Ron avatar
    48 posts
    Member since:
    Oct 2010

    Posted 06 Nov 2010 Link to this post

    I am developing a custom control and am trying to use RadStylesheetManager to embed the stylesheets in the assembly. This is what I have done so far:

    1. developed the custom control which registers the stylesheet to the stylesheetmanager in OnPreRender of the control like this

    RadStyleSheetManager.GetCurrent(Page).StyleSheets.Add(
       new StyleSheetReference("customstylesheet.css",
       System.Reflection.Assembly.GetAssembly(this.GetType()).FullName));

    2. added the stylesheet to the assembly

    [assembly: WebResource("MyCustomControl.customstylesheet.css", "text/css")]

    3. set the build action to Embedded Resource

    As far as I know that and should be all I need to do and so far everything seems to be looking fine and is working fine and dandy when I use the control in a web project. The resources are nicely retrieved via the WebResource.axd handler. The problem tough is that it ONLY works when I add my control design time. When I add the controls at runtime (in the page's init cycle), then the WebResource.axd handler reports a http error 500, specifically (curtosy of fiddler):

    <html>
        <head>
            <title>String cannot have zero length.</title>
            <style>
             body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
             p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
             b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
             H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
             H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
             pre {font-family:"Lucida Console";font-size: .9em}
             .marker {font-weight: bold; color: black;text-decoration: none;}
             .version {color: gray;}
             .error {margin-bottom: 10px;}
             .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
            </style>
        </head>
     
        <body bgcolor="white">
     
                <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
     
                <h2> <i>String cannot have zero length.</i> </h2></span>
     
                <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
     
                <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
     
                <br><br>
     
                <b> Exception Details: </b>System.ArgumentException: String cannot have zero length.<br><br>
     
                <b>Source Error:</b> <br><br>
     
                <table width=100% bgcolor="#ffffcc">
                   <tr>
                      <td>
                          <code>
     
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>
     
                      </td>
                   </tr>
                </table>
     
                <br>
     
                <b>Stack Trace:</b> <br><br>
     
                <table width=100% bgcolor="#ffffcc">
                   <tr>
                      <td>
                          <code><pre>
     
    [ArgumentException: String cannot have zero length.]
       System.Reflection.RuntimeAssembly.GetManifestResourceInfo(RuntimeAssembly assembly, String resourceName, ObjectHandleOnStack assemblyRef, StringHandleOnStack retFileName, StackCrawlMarkHandle stackMark) +0
       System.Reflection.RuntimeAssembly.GetManifestResourceInfo(String resourceName) +79
       Telerik.Web.UI.ScriptAssemblyInfo.get_AssemblyType() +64
       Telerik.Web.UI.<>c__DisplayClass2.<WriteScripts>b__0(Match match) +21
       System.Text.RegularExpressions.RegexReplacement.Replace(MatchEvaluator evaluator, Regex regex, String input, Int32 count, Int32 startat) +198
       System.Text.RegularExpressions.Regex.Replace(String input, MatchEvaluator evaluator, Int32 count, Int32 startat) +33
       System.Text.RegularExpressions.Regex.Replace(String input, MatchEvaluator evaluator) +38
       Telerik.Web.UI.CombinedScriptWriter.WriteScripts(List`1 scriptEntries, TextWriter outputWriter) +265
       Telerik.Web.UI.CombinedScriptWriter.WriteCombinedScriptFile() +1070
       Telerik.Web.UI.WebResource.ProcessRequest(HttpContext context) +74
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
    </pre></code>
     
                      </td>
                   </tr>
                </table>
     
                <br>
     
                <hr width=100% size=1 color=silver>
     
                <b>Version Information:</b> Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
     
                </font>
     
        </body>
    </html>
    <!--
    [ArgumentException]: String cannot have zero length.
       at System.Reflection.RuntimeAssembly.GetManifestResourceInfo(RuntimeAssembly assembly, String resourceName, ObjectHandleOnStack assemblyRef, StringHandleOnStack retFileName, StackCrawlMarkHandle stackMark)
       at System.Reflection.RuntimeAssembly.GetManifestResourceInfo(String resourceName)
       at Telerik.Web.UI.CombinedScriptWriter.ScriptAssemblyInfo.get_AssemblyType()
       at Telerik.Web.UI.CombinedScriptWriter.<>c__DisplayClass2.<WriteScripts>b__0(Match match)
       at System.Text.RegularExpressions.RegexReplacement.Replace(MatchEvaluator evaluator, Regex regex, String input, Int32 count, Int32 startat)
       at System.Text.RegularExpressions.Regex.Replace(String input, MatchEvaluator evaluator, Int32 count, Int32 startat)
       at System.Text.RegularExpressions.Regex.Replace(String input, MatchEvaluator evaluator)
       at Telerik.Web.UI.CombinedScriptWriter.WriteScripts(List`1 scriptEntries, TextWriter outputWriter)
       at Telerik.Web.UI.CombinedScriptWriter.WriteCombinedScriptFile()
       at Telerik.Web.UI.WebResource.ProcessRequest(HttpContext context)
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
    -->

    I have been banging into this for a couple of days now but can't seem to find the solution, so help is really appreciated. For the record, I have stepped throught the code and in the OnPreRender of my custom control the stylesheet reference looks to be added to the stylesheetmanager's stylesheet collection succesfully. A WebResource.axd link is generated indeed, so the manager 'thinks'  that something is registered indeed. But when retrieving the content of the resource it doesnt seem to find what it should be retrieving. 
    /*                    RadStyleSheetManager styleSheetManager = RadStyleSheetManager.GetCurrent(Page);
                        if (styleSheetManager == null) throw new HttpException("A styleSheetManager control must exist on the current page.");
                        styleSheetManager.StyleSheets.Add(
                            new StyleSheetReference("Inception.Web.RibbonBar.Skins." + this.SkinID + ".RibbonTabStrip.css",
                                                    System.Reflection.Assembly.GetAssembly(this.GetType()).FullName)); *
  2. Ron
    Ron avatar
    48 posts
    Member since:
    Oct 2010

    Posted 08 Nov 2010 Link to this post

    I just wanted to add that we are using the latest version of ASP.NET AJAX.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ron
    Ron avatar
    48 posts
    Member since:
    Oct 2010

    Posted 10 Nov 2010 Link to this post

    It turns out that it's really a non-issue. The problem was a silly typo (CAPS-LOCK ftw?!?) which caused the stylesheetmanager to try and find a resource that didnt exist. One thing that would have been really helpful in our search for the error, would be if the stylesheetmanager threw an exception when trying to register a non-existing resource. At the moment the stylesheetmanager seems to just ignore the faulty registration without any error.
  5. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 11 Nov 2010 Link to this post

    Hello Ron,

    It is good that you found the cause of the issue. It is also good to throw a specific exception in RadStyleSheetManager when it registers a non-existent web resource so that troubleshooting is easier in this case.

    We logged this as an improvement which we will make to the control in the future.

    I updated your Telerik points for your suggestion.

    Kind regards,
    Simon
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top