Html.Menu - Object Object reference not set to an instance of an object.

Oct 5, 2009 at 11:38 PM

Hi,

I've been using release 1.0 and got the occasional error when loading the sitemap when the app pool was loading so I just grabbed the latest version and now when I use:

<%=Html.Menu("d", "selected", new { id = "menu" })%>   

I always receive the following error:

 

 

[NullReferenceException: Object reference not set to an instance of an object.]
   MvcSiteMap.Core.Helpers.MenuHelper.Menu(HtmlHelper helper, String providerName, Boolean showStartingNode, Int32 startingNodeLevel, Boolean startFromCurrentNode, String menuCssClass, String selectedMenuItemCssClass, Object menuHtmlAttributes) +1738
   MvcSiteMap.Core.Helpers.MenuHelper.Menu(HtmlHelper helper, String providerName, Boolean showStartingNode, Boolean startFromCurrentNode, String menuCssClass, String selectedMenuItemCssClass, Object menuHtmlAttributes) +87
   MvcSiteMap.Core.Helpers.MenuHelper.Menu(HtmlHelper helper, Boolean showStartingNode, Boolean startFromCurrentNode, String menuCssClass, String selectedMenuItemCssClass, Object menuHtmlAttributes) +110
   MvcSiteMap.Core.Helpers.MenuHelper.Menu(HtmlHelper helper, String menuCssClass, String selectedMenuItemCssClass, Object menuHtmlAttributes) +79
   ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in g:\Dev_SourceCode\BarkWeb\TCWS\src\Barbour\Views\Shared\Site.Master:89
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   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) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29
   System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +59
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

 

Here's my sitemap file:

 

<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
  <mvcSiteMapNode title="List Jobs" controller="Proofing" action="Index" isDynamic="false" dynamicParameters="*">
    <mvcSiteMapNode title="Create" controller="Proofing" action="Create" />
    <mvcSiteMapNode title="Category Admin" controller="Admin" action="Index" />    
    <!--<mvcSiteMapNode title="Products" controller="Products">
      <mvcSiteMapNode title="Will be replaced in controller"
                      controller="Products" action="List"
                      isDynamic="true" dynamicParameters="id"
                      key="ProductsListCategory"/>
    </mvcSiteMapNode>-->
    <!--<mvcSiteMapNode title="List Job" controller="Proofing" action="Index">
      <mvcSiteMapNode title="Create" controller="Proofing" action="Create" />
    </mvcSiteMapNode>-->

    <mvcSiteMapNode title="User Management" controller="Membership">
      <mvcSiteMapNode title="Login" controller="Membership" action="LogOn" />
      <mvcSiteMapNode title="Account Creation" controller="Membership" action="Register" />
      <mvcSiteMapNode title="Change Password" controller="Membership" action="ChangePassword" />
      <mvcSiteMapNode title="Logout" controller="Membership" action="LogOff" />
    </mvcSiteMapNode>
    <mvcSiteMapNode title="Change Password" controller="Account" action="ChangePassword" />    
  </mvcSiteMapNode>
</siteMap>

I've had a quick look at debugging the code which indicates a null SiteMap.CurrentNode object but couldn't quickly see why.

Any help would be appreciated before I go back to good old if statements.

Thanks

Dan

 

 

 

 

 

Coordinator
Oct 6, 2009 at 6:11 AM

Is this only at start of the application or does it occur on other moments as well?

Oct 6, 2009 at 7:56 AM

Hi,

With the old version it was occasionally on startup and I think it looks like something to do with when the app pool first starts as it was ok after but in the latest version it happens every time at application startup.

Thanks

Dan

Coordinator
Oct 6, 2009 at 8:52 AM

Have you added the defaultCOntroller and defaultAction settings in web.config?

 

    <siteMap defaultProvider="MvcSiteMap">
			<providers>
				<add name="MvcSiteMap"
             type="MvcSiteMap.Core.MvcSiteMapProvider"
             siteMapFile="~/Web.Sitemap"
             securityTrimmingEnabled="true"
             enableLocalization="true"
             cacheDuration="10"
             scanAssembliesForSiteMapNodes="true"
             treatAttributesAsRouteValues="true"
             defaultControllerName="Home"
             defaultActionName="Index"
             aclModule="MvcSiteMap.Core.DefaultMvcSiteMapAclModule, MvcSiteMap.Core"/>
			</providers>
		</siteMap>

 

 

Coordinator
Oct 6, 2009 at 8:56 AM

Can you post a project reproducing this issue?

Oct 6, 2009 at 9:06 AM

I tried adding the defaultController but I still get the same problem, I've zipped up the project so I can send it to you if tha'ts ok?  What's your email?

Thanks

Dan

Coordinator
Oct 6, 2009 at 9:43 AM

You can create an issue on the issue tracker and attach the project. If confidential, contact me through CodePlex and I'll give you my e-mail addess.