NullReferenceException when trying to generate menu for MvcSiteMap 3.0

Dec 29, 2010 at 3:32 PM

Line 3: <nav>

Line 4: <span id="sideMenu">

Line 5: <%= Html.MvcSiteMap().Menu(SiteMap.Provider.FindSiteMapNodeFromKey("Operations"), true, false,2)%>

Line 6: </span>

Line 7: </nav>

 

[NullReferenceException: Object reference not set to an instance of an object.] MvcSiteMapProvider.DefaultSiteMapProvider.BuildSiteMap() +205

 

If you remember I was using V 2.2.1 without problems but I wanted to use v3 for route feature, but I can't get it working.

Dec 30, 2010 at 6:55 AM

Can you post your sitemap node, routes and stacktrace of the error?

Feb 4, 2011 at 1:51 PM

Same issue...

Stack trace

[NullReferenceException: Object reference not set to an instance of an object.]
   MvcSiteMapProvider.DefaultSiteMapProvider.BuildSiteMap() in c:\Projects\Codeplex\TFS10\mvcsitemap\Branches\3.0.0\src\MvcSiteMapProvider\MvcSiteMapProvider\DefaultSiteMapProvider.cs:0

[MvcSiteMapException: An error occured while building the sitemap... Check the InnerException for more details.]
   MvcSiteMapProvider.DefaultSiteMapProvider.BuildSiteMap() in c:\Projects\Codeplex\TFS10\mvcsitemap\Branches\3.0.0\src\MvcSiteMapProvider\MvcSiteMapProvider\DefaultSiteMapProvider.cs:563
   System.Web.StaticSiteMapProvider.FindSiteMapNode(String rawUrl) +120
   MvcSiteMapProvider.DefaultSiteMapProvider.FindSiteMapNode(HttpContext context, RouteData routeData) in c:\Projects\Codeplex\TFS10\mvcsitemap\Branches\3.0.0\src\MvcSiteMapProvider\MvcSiteMapProvider\DefaultSiteMapProvider.cs:1013
   MvcSiteMapProvider.DefaultSiteMapProvider.FindSiteMapNode(HttpContext context) in c:\Projects\Codeplex\TFS10\mvcsitemap\Branches\3.0.0\src\MvcSiteMapProvider\MvcSiteMapProvider\DefaultSiteMapProvider.cs:980
   System.Web.SiteMapProvider.get_CurrentNode() +56
   MvcSiteMapProvider.Web.Html.SiteMapPathHelper.SiteMapPath(MvcSiteMapHtmlHelper helper, String templateName) in c:\Projects\Codeplex\TFS10\mvcsitemap\Branches\3.0.0\src\MvcSiteMapProvider\MvcSiteMapProvider\Web\Html\SiteMapPathHelper.cs:0
   MvcSiteMapProvider.Web.Html.SiteMapPathHelper.SiteMapPath(MvcSiteMapHtmlHelper helper) in c:\Projects\Codeplex\TFS10\mvcsitemap\Branches\3.0.0\src\MvcSiteMapProvider\MvcSiteMapProvider\Web\Html\SiteMapPathHelper.cs:33
...

Sitemap file

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-2.0" enableLocalization="true">
  <mvcSiteMapNode title="Home" controller="Dashboard" action="Index">
</mvcSiteMap>

Routes (Global.ascx)

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Dashboard", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
                new[] {"MvcLaundryManager.Controllers"}
            );

        }

 

 

 


<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-2.0" enableLocalization="true">
  <mvcSiteMapNode title="Home" controller="Dashboard" action="Index">
Feb 4, 2011 at 2:05 PM

It looks like the root namespace on the Sitemap file was causing the issue: I uninstalled the package via NuGet, removed any trace of MvcSitemap config and view files then re-installed.

Might be asking a bit much, but would be good if you could push an update to the root namespace of existing Sitemap files, or create backup of existing file and place a new one alongside :) it's one of these sneaky little issues/changes that one could spend an age trying to debug!

Feb 4, 2011 at 2:45 PM

True, another one is coming for 3.0.0 :-)

Feb 9, 2011 at 2:39 PM

same problem..

Feb 13, 2011 at 9:20 PM

Rather than uninstalling the entire package, simply re pointing the root namespace from

MvcSiteMap-File-2.0
 to
MvcSiteMap-File-3.0
 in the site map file seems to work a treat.

<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
  <mvcSiteMapNode title="Home" controller="Dashboard" action="Index">
</mvcSiteMap>

:)

Dec 7, 2011 at 4:58 AM

I've registered the sitemap provider by Nuget but this error still appears

Object reference not set to an instance of an object.

[NullReferenceException: Object reference not set to an instance of an object.]
   MvcSiteMapProvider.DefaultSiteMapProvider.FindSiteMapNode(HttpContext context, RouteData routeData) in c:\Projects\Codeplex\TFS10\mvcsitemap\Branches\3.1.0\src\MvcSiteMapProvider\MvcSiteMapProvider\DefaultSiteMapProvider.cs:1085
   MvcSiteMapProvider.DefaultSiteMapProvider.FindSiteMapNode(HttpContext context) in c:\Projects\Codeplex\TFS10\mvcsitemap\Branches\3.1.0\src\MvcSiteMapProvider\MvcSiteMapProvider\DefaultSiteMapProvider.cs:1047
   System.Web.SiteMapProvider.get_CurrentNode() +56

 

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
  <mvcSiteMapNode title="Home" controller="Home" action="Index">
    <mvcSiteMapNode title="About" controller="Home" action="About"/>
  </mvcSiteMapNode>
</mvcSiteMap>

In masterpage:

@Html.MvcSiteMap().Menu()

 Web.config:

<pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
        <add namespace="MvcSiteMapProvider.Web.Html" />
      </namespaces>
    </pages>
    <siteMap defaultProvider="MvcSiteMapProvider" enabled="true">
      <providers>
        <clear />
        <add name="MvcSiteMapProvider" type="MvcSiteMapProvider.DefaultSiteMapProvider, MvcSiteMapProvider" siteMapFile="~/Mvc.Sitemap" securityTrimmingEnabled="true" cacheDuration="5" enableLocalization="true" scanAssembliesForSiteMapNodes="true" includeAssembliesForScan="" excludeAssembliesForScan="" attributesToIgnore="visibility" nodeKeyGenerator="MvcSiteMapProvider.DefaultNodeKeyGenerator, MvcSiteMapProvider" controllerTypeResolver="MvcSiteMapProvider.DefaultControllerTypeResolver, MvcSiteMapProvider" actionMethodParameterResolver="MvcSiteMapProvider.DefaultActionMethodParameterResolver, MvcSiteMapProvider" aclModule="MvcSiteMapProvider.DefaultAclModule, MvcSiteMapProvider" siteMapNodeUrlResolver="MvcSiteMapProvider.DefaultSiteMapNodeUrlResolver, MvcSiteMapProvider" siteMapNodeVisibilityProvider="MvcSiteMapProvider.DefaultSiteMapNodeVisibilityProvider, MvcSiteMapProvider" siteMapProviderEventHandler="MvcSiteMapProvider.DefaultSiteMapProviderEventHandler, MvcSiteMapProvider" />
      </providers>
    </siteMap>

Web.config in View folder:

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="MvcSiteMapProvider.Web.Html" />
        <add namespace="MvcSiteMapProvider.Web.Html.Models" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

Could you please help me?