1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Invalid Resource Name trying to tie Designer to Control

Invalid Resource Name trying to tie Designer to Control

6 posts, 0 answered
  1. Travis
    Travis avatar
    86 posts
    Registered:
    15 Oct 2008
    22 Jan 2013
    Link to this post
    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 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.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.
     
    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:
     
    [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) +1421
    Telerik.Sitefinity.Web.UI.ControlUtilities.GetControlTemplate(TemplateInfo info) +1309
    Telerik.Sitefinity.Web.UI.ControlUtilities.GetTemplate(TemplateInfo info) +83
    Telerik.Sitefinity.Web.UI.SimpleView.get_LayoutTemplate() +261
    Telerik.Sitefinity.Web.UI.SimpleView.get_Container() +54
    Telerik.Sitefinity.Web.UI.SimpleView.CreateChildControls() +72
    System.Web.UI.Control.EnsureChildControls() +102
    System.Web.UI.Control.PreRenderRecursiveInternal() +42
    System.Web.UI.Control.PreRenderRecursiveInternal() +175
    System.Web.UI.Control.PreRenderRecursiveInternal() +175
    System.Web.UI.Control.PreRenderRecursiveInternal() +175
    System.Web.UI.Control.PreRenderRecursiveInternal() +175
    System.Web.UI.Control.PreRenderRecursiveInternal() +175
    System.Web.UI.Control.PreRenderRecursiveInternal() +175
    System.Web.UI.Control.PreRenderRecursiveInternal() +175
    System.Web.UI.Control.PreRenderRecursiveInternal() +175
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496
     
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

    Now, my immediate thought is "hey, your virtual path is not configured properly" or "your ascx file is not set as an embeddable resource", but, it seems the virtual path is configured properly, as I can access the javascript file in this same folder, and my control works fine once dropped on the page, and my ascx file is definitely set as an embeddable resource.

    My designer is defined as follows:

    using 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;
            }
        }
    }

    My Control which I want to use my designer is defined as:

    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();
     
            }
        }
    }

    The reference to my control in toolboxesconfig.config is

    <add enabled="True" type="WebsiteControls.Controls.BlogPostControl, WebsiteControls" title="BlogPost" cssClass="sfBrandsListIcn" visibilityMode="None" name="BlogPost" />

    and my virtual path (which I can confirm works, at least for the control which lives in this same class library)

    <add resourceLocation="WebsiteControls, WebsiteControls" resolverName="EmbeddedResourceResolver" virtualPath="~/WebsiteControls/*" />

    I'm just not sure why I'm getting this error. My template for my designer is not empty, it has some content on it, and I believe the virtual path is setup correctly, so what's the issue?

    Appreciate any help that anyone might be able to offer. My Class Library is available for download here: http://uldev02.urbanlighthouse.com/TravelIdeas/WebControls.zip.
  2. Travis
    Travis avatar
    86 posts
    Registered:
    15 Oct 2008
    24 Jan 2013
    Link to this post
    Any suggestions at all?
  3. Patrick Dunn
    Patrick Dunn avatar
    237 posts
    Registered:
    03 Nov 2014
    25 Jan 2013
    Link to this post
    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")]

    Let me know if this doesn't help. Kind regards,
    Patrick Dunn
    the Telerik team
  4. Travis
    Travis avatar
    86 posts
    Registered:
    15 Oct 2008
    25 Jan 2013
    Link to this post

    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

  5. Travis
    Travis avatar
    86 posts
    Registered:
    15 Oct 2008
    29 Jan 2013 in reply to Travis
    Link to this post

    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) +3060

    The 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?

  6. Patrick Dunn
    Patrick Dunn avatar
    237 posts
    Registered:
    03 Nov 2014
    30 Jan 2013
    Link to this post
    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
6 posts, 0 answered