Invalid Resource Name trying to tie Designer to Control
Hello,
I am setting up some controls for my Sitefinity 5.3 project in their own class library. I have set up my Virtual Path and Toolboxes file to reference these controls in my class library, and it works well. I've also created a custom designer for my control, which lives in this class library as well. However, when it tries to access the template for the designer, I get the following exception:
Server Error in '/' Application.Invalid resource name"~/WebsiteControls/WebsiteControls.Controls.BlogPost.Designer.BlogPostDesigner.ascx"for assembly "WebsiteControls, Version=1.0.0.0, Culture=neutral,PublicKeyToken=null" or empty template.Description: An unhandled exception occurred duringthe execution of the current web request. Please review the stack tracefor more information about the error and where it originated in thecode.Exception Details: System.ArgumentException: Invalidresource name"~/WebsiteControls/WebsiteControls.Controls.BlogPost.Designer.BlogPostDesigner.ascx"for assembly "WebsiteControls, Version=1.0.0.0, Culture=neutral,PublicKeyToken=null" or empty template.Source Error:An unhandled exception was generated during the execution of the currentweb request. Information regarding the origin and location of theexception can be identified using the exception stack trace below.Stack Trace:[ArgumentException: Invalid resource name "~/WebsiteControls/WebsiteControls.Controls.BlogPost.Designer.BlogPostDesigner.ascx" for assembly "WebsiteControls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" or empty template.]Telerik.Sitefinity.Web.UI.ControlUtilities.GetTemplate(String virtualPath, String resourceFileName, Type assemblyInfo, String templateDeclaration, Boolean addChildrenAsDirectDescendants) +1421Telerik.Sitefinity.Web.UI.ControlUtilities.GetControlTemplate(TemplateInfo info) +1309Telerik.Sitefinity.Web.UI.ControlUtilities.GetTemplate(TemplateInfo info) +83Telerik.Sitefinity.Web.UI.SimpleView.get_LayoutTemplate() +261Telerik.Sitefinity.Web.UI.SimpleView.get_Container() +54Telerik.Sitefinity.Web.UI.SimpleView.CreateChildControls() +72System.Web.UI.Control.EnsureChildControls() +102System.Web.UI.Control.PreRenderRecursiveInternal() +42System.Web.UI.Control.PreRenderRecursiveInternal() +175System.Web.UI.Control.PreRenderRecursiveInternal() +175System.Web.UI.Control.PreRenderRecursiveInternal() +175System.Web.UI.Control.PreRenderRecursiveInternal() +175System.Web.UI.Control.PreRenderRecursiveInternal() +175System.Web.UI.Control.PreRenderRecursiveInternal() +175System.Web.UI.Control.PreRenderRecursiveInternal() +175System.Web.UI.Control.PreRenderRecursiveInternal() +175System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web.UI;using Telerik.Sitefinity.Web.UI;using Telerik.Sitefinity.Web.UI.ControlDesign;using System.Configuration;namespace WebsiteControls.Controls.BlogPost public class BlogPostDesigner : ControlDesignerBase private const string layoutTemplateName = "WebsiteControls.Controls.BlogPost.Designer.BlogPostDesigner.ascx"; private const string scriptref = "WebsiteControls.Controls.BlogPost.Designer.BlogPostDesigner.js"; protected override string LayoutTemplateName get return ConfigurationManager.AppSettings.Get("WebsiteControls_VirtualPath") + layoutTemplateName; protected override Type ResourcesAssemblyInfo get return this.GetType(); public override IEnumerable<System.Web.UI.ScriptReference> GetScriptReferences() var res = new List<ScriptReference>(base.GetScriptReferences()); var assemblyName = this.GetType().Assembly.GetName().ToString(); res.Add(new ScriptReference(ConfigurationManager.AppSettings.Get("WebsiteControls_VirtualPath") + scriptref, assemblyName)); return res.ToArray(); protected override void InitializeControls(GenericContainer container) this.DesignerMode = ControlDesignerModes.Simple; using System;using System.Collections.Generic;using System.Linq;using System.Text;using Telerik.Sitefinity.Web.UI.ContentUI.Views.Backend;using System.Web.UI;using System.Configuration;using Telerik.Sitefinity.Web.UI;using Telerik.Sitefinity.Modules.Pages.Web.UI;using Telerik.Sitefinity.Web.UI.ControlDesign;namespace WebsiteControls.Controls [RequireScriptManager,ControlDesigner(typeof(WebsiteControls.Controls.BlogPostDesigner))] public class BlogPostControl : ViewBase private const string layoutTemplateName = "WebsiteControls.Controls.BlogPost.BlogPostControl.ascx"; private const string scriptref = "WebsiteControls.Controls.BlogPost.BlogPostControl.js"; public void Page_Load() //Response.Write("a"); protected override string LayoutTemplateName get return layoutTemplateName; public override string LayoutTemplatePath get return ConfigurationManager.AppSettings.Get("WebsiteControls_VirtualPath") + layoutTemplateName; set base.LayoutTemplatePath = value; protected override void InitializeControls(GenericContainer container, Telerik.Sitefinity.Web.UI.ContentUI.Contracts.IContentViewDefinition definition) try catch /*protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container) //set the partnerID try catch //TestParnerID(); */ public override void RenderBeginTag(HtmlTextWriter writer) if (!string.IsNullOrEmpty(this.CssClass)) this.AddAttributesToRender(writer); writer.RenderBeginTag(HtmlTextWriterTag.Div); public override void RenderEndTag(HtmlTextWriter writer) if (!string.IsNullOrEmpty(this.CssClass)) base.RenderEndTag(writer); public override IEnumerable<System.Web.UI.ScriptReference> GetScriptReferences() var scripts = base.GetScriptReferences() as List<ScriptReference>; if (scripts == null) return base.GetScriptReferences(); scripts.Add(new ScriptReference(ConfigurationManager.AppSettings.Get("WebsiteControls_VirtualPath") + scriptref)); return scripts.ToArray(); <add enabled="True" type="WebsiteControls.Controls.BlogPostControl, WebsiteControls" title="BlogPost" cssClass="sfBrandsListIcn" visibilityMode="None" name="BlogPost" /><add resourceLocation="WebsiteControls, WebsiteControls" resolverName="EmbeddedResourceResolver" virtualPath="~/WebsiteControls/*" />Any suggestions at all?
Hello Travis,
Thanks for using Sitefinity!
Your javascript also needs to be registered as a web resource and it must be set as an embedded resource as well. Can you check ~/Properties/AssemblyInfo.cs for the following line:
[assembly: WebResource("YOUR_ASSEMBLY_.js", "application/x-javascript")]Hi Patrick
Thanks for your reply. Unfortunately, this is unrelated to the issue I'm experiencing. My Javascript file IS referenced in my AssemblyInfo.cs file, and in order to ensure this was not what was causing the issue, i removed the references which loaded this javascript file, and the issue persisted.
The reference in my Assembly file is as follows:
[assembly: WebResource("WebsiteControls.Controls.BlogPost.Designer.BlogPostDesigner.js", "application/x-javascript")]
Like I said, this seems to be unrelated to the issue at hand. Do you have any other suggestions that might be causing this problem?
Thanks
Hello,
I had overridden the wrong property in my designer. Instead of overriding the LayoutTemplatePath, I overwrote the LayoutTemplateName variable. Now, I'm getting a new exception that I'm not sure of the cause of. Now, I get this:
Object reference not set to an instance of an object.Description: 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.Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error: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.Stack Trace:[NullReferenceException: Object reference not set to an instance of an object.] Telerik.Sitefinity.Web.UI.ControlDesign.GenericCollectionConverter.GetProperties(ITypeDescriptorContext context, Object value, Attribute[] attributes) +106 System.ComponentModel.TypeConverter.GetProperties(Object value) +72 Telerik.Sitefinity.Modules.Pages.Web.Services.WcfPropertyManager.GetChildProperties(PropertyDescriptor propertyDescriptor, Object instance) +180 Telerik.Sitefinity.Modules.Pages.Web.Services.WcfPropertyManager.AddPropertiesRecursively(Object instance, IList`1 list, List`1 propertyDescriptorHierarchy, ControlData controlData, Int32 depth, CultureInfo culture) +688 Telerik.Sitefinity.Modules.Pages.Web.Services.WcfPropertyManager.AddPropertiesRecursively(Object instance, IList`1 list, List`1 propertyDescriptorHierarchy, ControlData controlData, Int32 depth, CultureInfo culture) +910 Telerik.Sitefinity.Modules.Pages.Web.Services.WcfPropertyManager.AddPropertiesRecursively(Object instance, IList`1 list, List`1 propertyDescriptorHierarchy, ControlData controlData, Int32 depth, CultureInfo culture) +910 Telerik.Sitefinity.Modules.Pages.Web.Services.WcfPropertyManager.GetProperties(Object instance, ControlData controlData, Int32 depth, String parentPropertyPath, CultureInfo culture) +436 Telerik.Sitefinity.Web.UI.PropertyEditor.GetPropertyBag() +284 Telerik.Sitefinity.Web.UI.PropertyEditor.GetScriptDescriptors() +1124 System.Web.UI.ScriptControlManager.RegisterScriptDescriptors(IScriptControl scriptControl) +128 System.Web.UI.ScriptManager.RegisterScriptDescriptors(IScriptControl scriptControl) +49 Telerik.Sitefinity.Web.UI.AjaxDialogBase.Render(HtmlTextWriter writer) +117 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8 System.Web.UI.Control.Render(HtmlTextWriter writer) +10 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208 System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +173 System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +31 System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +53 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100 System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8 System.Web.UI.Page.Render(HtmlTextWriter writer) +29 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3060The error occurs at some point after it has retrieved the ScriptReferences, but before it has retrieve the ScriptDescriptors for the designer. Does anyone have any ideas as to what's causing this new error?
Hi Travis,
Sorry to hear you're still having problems. Judging from the stack trace the error is thrown in the GetProperties method that is generating your Property Descriptor Collection. This is called by GetScriptDescriptors and I believe it indicates your descriptor collection is empty. I don't see the implementation of GetScriptDescriptors() in the below code, but make sure to check it returns the collection of descriptors properly and with the proper type.
Have you looked over Josh's blog post on widget designers? It contains all the information necessary to develop a custom designer without using SF Thunder - take a closer look at the GetScriptDescriptors method as this is most probably what is throwing this exception
All the best,
Patrick Dunn
the Telerik team