Menu control throws NullReferenceException

Posted by Community Admin on 04-Aug-2018 16:33

Menu control throws NullReferenceException

All Replies

Posted by Community Admin on 23-Dec-2014 00:00

I've updated from 6.2 to7.3.5610.0. After this update the normal ASP.NET menu control is no longer working. I've created a new empty sitefinity project and created a masterpage with a ASP.NET menu control. This results in the same error. 

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="SitefinityWebApp.Site1" %>
  
<!DOCTYPE html>
  
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1"></asp:Menu>
            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>
  
 
[NullReferenceException: Object reference not set to an instance of an object.]
   System.Web.UI.WebControls.Menu.DataBindRecursive(MenuItem node, IHierarchicalEnumerable enumerable) +1932
   System.Web.UI.WebControls.Menu.DataBindItem(MenuItem item) +315
   System.Web.UI.WebControls.Menu.PerformDataBinding() +124
   System.Web.UI.WebControls.HierarchicalDataBoundControl.PerformSelect() +102
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
   System.Web.UI.WebControls.Menu.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
   System.Web.UI.WebControls.Menu.EnsureDataBound() +34
   System.Web.UI.WebControls.Menu.OnPreRender(EventArgs e) +24
   System.Web.UI.Control.PreRenderRecursiveInternal() +83
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974

 

Posted by Community Admin on 26-Dec-2014 00:00

Hello Bart,

Thank you for contacting us.

I reproduces the issue on Sitefinity 7.3 on my side and verified that in Sitefinity 6.2 the same case was working. However, when I moved the Menu control and the SiteMapDataSource out of the asp:ContentPlaceHolder everything was okay.

<div id="Content">
     Menu:
    <asp:Menu ID="Menu1" runat="server" RenderingMode="Table"></asp:Menu>
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
 
    <asp:ContentPlaceHolder id="Content" runat="server">
    </asp:ContentPlaceHolder>
</div>

I am setting the Data Source of the Menu on Page_Load like this: 

public partial class Site1 : System.Web.UI.MasterPage
    protected void Page_Load(object sender, EventArgs e)
    
        this.SiteMapDataSource1 = new SitefinitySiteMapDataSource();
        this.SiteMapDataSource1.Provider = SiteMapBase.GetSiteMapProvider("FrontendSiteMap");
        this.SiteMapDataSource1.ShowStartingNode = false;
        this.Menu1.DataSource = this.SiteMapDataSource1;
        this.Menu1.DataBind();
    

I will contact our developers after the holidays to check if this behaviour is an intended change or a bug.

Regards,
Kristian Smilenov
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 28-Dec-2014 00:00

Hi Kristian,

Thanks for looking into this. I cannot easily move the menu control outside the contentplaceholder as I'm using nested masterpages.

I'm looking forward to the developer's response.

 

Regards,

 

Bart Vanlier

Posted by Community Admin on 11-Jan-2015 00:00

Any news regarding this issue?

Another issue I've got, probably related to this, is when i try to set StartingNodeUrl I get an ArgumentException telling me I'm not allowed to set the relative path "~/Custom/Controls/WebFront/". I've tried several setting several url's but I keep getting this exception.

Posted by Community Admin on 13-Jan-2015 00:00

There seems to be something wrong with my database. When I delete all pages and create new ones, the problem goes away.

Any help would be greatly appreciated as recreating all pages is not really an option.

This thread is closed