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

Forums / Developing with Sitefinity / Problem with designer, array out of bounds message

Problem with designer, array out of bounds message

7 posts, 0 answered
  1. Henrik
    Henrik avatar
    20 posts
    Registered:
    10 Jun 2010
    20 Jul 2010
    Link to this post
    Hi,

    I created my custom menu with no fluff as I wanted as a custom control and uploaded the dll file to the server. I can drag and drop it like I should be able to and it goes get inserted, the properties work and you can see it on the live site as well (it renders well, too). However, in the designer I get a the message "Index was outside the bounds of the array". I'm fairly certain it's not from my own code as I don't index into arrays at all and have enabled the debugger to catch that exception despite it being user-handled.

    How can I resolve the issue/get a stack-trace?

    Cheers
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    20 Jul 2010
    Link to this post
    Hello Henrik,

    This type of error is  thrown by the .NET Framework, when you are accessing an item in an indexed object and the accessed index is out of bounds.  Most probably you have an ArrayList and you are trying to access an index that is not available. It looks like at the time your are trying to retrieve the data the control has no items. The problem is most probably related to the way you are binding this control and in which stage of its lifecycle you are doing this. You could attach your code to VS debugger and see when and why the error is raised. Note that in Edit mode the Page is null, so this could be one of the reasons for this issue. You could check if the page is null where you bind your data, so that you will escape the page edit mode and the error will not be thrown.

    Best wishes,
    Ivan Dimitrov
    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
  3. Henrik
    Henrik avatar
    20 posts
    Registered:
    10 Jun 2010
    21 Jul 2010
    Link to this post
    Hello Ivan and thanks for your reply.

    > Most probably you have an ArrayList and you are trying to access an index that is not available
    This is not the case as I don't index into any arrays manually/in my own code.

    > It looks like at the time your are trying to retrieve the data the control has no items. The problem is most probably related to the way you are binding this control and in which stage of its lifecycle you are doing this.

    This is probably more like it. I don't have any controls in the user control. I only use the render event to render the html and all html is generated through C#.

    Only the c'tor is being run in edit-page mode, never the overridden Render...

    Any ideas?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 Jul 2010
    Link to this post
    Hi Henrik,

    Can you share a sample code that I can use to see the issue?


    Regards,
    Ivan Dimitrov
    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
  5. Henrik
    Henrik avatar
    20 posts
    Registered:
    10 Jun 2010
    21 Jul 2010
    Link to this post
    Testing.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Testing.ascx.cs"
        Inherits="Sample.Testing"
        EnableViewState="false" %>

    Testing.ascx.cs
    using System.Web;
    using System.Web.Caching;
    using System.Web.UI;
    using Telerik.Caching;
    using Telerik.Cms.Web;
    using Telerik.Web.UI;
     
    namespace Sample
    {
        public partial class Testing : UserControl, ICacheableObject
        {
            private readonly RadSiteMapDataSource _SiteMapSource;
     
            public Testing()
            {
                _SiteMapSource = new RadSiteMapDataSource();
            }
     
            protected override void Render(HtmlTextWriter ww)
            {
                ww.Write("Hello world!");
            }
     
            private CmsSiteMapProvider GetProvider()
            {
                return string.IsNullOrEmpty(_SiteMapSource.SiteMapProvider)
                        ? SiteMap.Provider as CmsSiteMapProvider
                        : SiteMap.Providers[_SiteMapSource.SiteMapProvider] as CmsSiteMapProvider;
            }
     
            #region ICacheableObject Members
     
            public CacheDependency[] GetDependencies()
            {
                var provider = GetProvider();
                return provider != null ? new[] {provider.CloneCacheDependency()} : null;
            }
     
            #endregion
        }
    }

    Add the above to a new C# assembly. Mark the ascx as Embedded Resource.

    Upload it.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 Jul 2010
    Link to this post
    Hello Henrik,

    I set up the code you sent and it does not produce any error at my end. The problem comes from another control or there is some other logic in your control. You could set EnableViewState to true and control view state behavior from the control designer.

    Regards,
    Ivan Dimitrov
    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
  7. Henrik
    Henrik avatar
    20 posts
    Registered:
    10 Jun 2010
    21 Jul 2010
    Link to this post
    Hello,

    I found the solution. I'm a bit rusty on web forms as I haven't done them in about 3 years. I needed to make my control inherit WebControl/Control rather than UserControl+ascx-file and it all works out great.

    Regards,
    Henrik
Register for webinar
7 posts, 0 answered