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
2. added the stylesheet to the assembly
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):
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.
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.