NullReferenceException on MvcSiteMapProvider on production

The problem is that I regularly get an error in the workplace (ASP.NET MVC 3), but cannot reproduce this error locally. Exception text:

ExceptionType: System.NullReferenceException
Message: Object reference not set to an instance of an object.
StackTrace:
   at System.Collections.Specialized.NameObjectCollectionBase.BaseGetAllKeys()
   at System.Collections.Specialized.NameValueCollection.get_AllKeys()
   at MvcSiteMapProvider.MvcSiteMapNode.get_MetaAttributes()
   at MvcSiteMapProvider.Web.Html.SiteMapNodeModelMapper.MapToSiteMapNodeModel(SiteMapNode node, MvcSiteMapNode mvcNode, IDictionary`2 sourceMetadata)
   at MvcSiteMapProvider.Web.Html.SiteMapPathHelper.BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode)
   at MvcSiteMapProvider.Web.Html.SiteMapPathHelper.SiteMapPath(MvcSiteMapHtmlHelper helper, String templateName)
   at ASP._Page_Views_Shared__LoggedInLayout_cshtml.Execute() in c:\Solution\Sites\Project2Site\Views\Shared\_LoggedInLayout.cshtml:line 86
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.WebPages.WebPageBase.Write(HelperResult result)
   at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body)
   at System.Web.WebPages.WebPageBase.PopContext()
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)

      

I have no such errors. Here I am calling the method MvcSiteMap().SiteMapPath()

:

enter image description here

Maybe someone else had the same problem before. If so, please share your solution.

Thanks in advance.

0


source to share


1 answer


This won't answer your question directly, but it might help you on your way to debugging the problem as this only happens in production, not in dev / debug.

Consider replacing your string:

@Html.MvcSiteMap().SiteMapPath()

      



With something like:

@SafeBreadCrumb()

@helper SafeBreadCrumb() {
    MvcHtmlString output;
    try
    {
        output = Html.MvcSiteMap().SiteMapPath();
    }
    catch (Exception e)
    {
        output = new MvcHtmlString(e.Message);    
    }
    <text>@output</text>
}

      

Feels a little messy, but it's easier than grabbing the MvcSiteMapProvider source and sticking some logs! If this happened while debugging, you wouldn't need to do it. Also, it's just a change in view, so no recompilation is required.

+2


source







All Articles