2012-09-24 46 views
0

问题是我经常在生产站点(ASP.NET MVC 3)得到错误,但不能在本地重现此错误。 例外的文字是:在生产MvcSiteMapProvider NullReferenceException

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) 

我在本地没有这样的错误。这里就是我调用MvcSiteMap().SiteMapPath()方法:

enter image description here

可能是有人有过同样的问题。如果有,请分享您的解决方案。

在此先感谢。

+1

您是否已经检出了[Github](https://github.com/maartenba/MvcSiteMapProvider)目前托管此项目的问题页,或者[Codeplex]上的讨论论坛(http:// mvcsitemap.codeplex .com /讨论)以前托管的地方?如果是这样,你可以添加一些关于你可能添加的动态节点的更多信息。或者所有的站点地图节点都是在Mvc.sitemap文件中定义的? –

+0

我已经检查了Github和Codeplex上的这个问题,但没有找到具有相同堆栈跟踪的问题。所有节点都在Mvc.Sitemap文件中定义。 –

+0

您可以发布您的Mvc.sitemap文件的内容。我知道这个理论是,你在这里有什么不应该是错的,因为它在调试但不是在生产中工作,但可能会提供一些线索。 –

回答

2

这不会直接回答你的问题,但可能会帮助你调试问题的路径,因为它只发生在生产中,而不是在dev/debug中。

考虑更换行:

@Html.MvcSiteMap().SiteMapPath() 

的东西,如:

@SafeBreadCrumb() 

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

感觉有点脏,但它比抓住MvcSiteMapProvider的来源,在一些伐木坚持更轻松!如果它发生在调试中,则不需要尝试此操作。另外它只是一个视图更改,所以不需要重新编译。