移动到生产时,MVCSiteMapProvider提供空引用

时间:2014-02-05 19:01:29

标签: nullreferenceexception mvcsitemapprovider

我正在使用MVCSiteMapProvider 4.4.9.0编写MVC 4.5应用程序。在运行Visual Studio开发服务器的Visual Studio中进行开发时,一切都按预期工作。但是,在将项目发布到生产服务器之后,我遇到了NullReferenceException。这是调用堆栈。 (对不起,没有足够的声望点发布屏幕截图)

Server Error in '/' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[NullReferenceException: Object reference not set to an instance of an object.]
   MvcSiteMapProvider.Reflection.MvcSiteMapNodeAttributeDefinitionProvider.GetAttributeDefinitionsForControllers(Type type) +71
   MvcSiteMapProvider.Reflection.MvcSiteMapNodeAttributeDefinitionProvider.GetMvcSiteMapNodeAttributeDefinitions(IEnumerable`1 assemblies) +168
   MvcSiteMapProvider.DI.SiteMapNodeFactoryContainer.GetMvcSiteMapNodeAttributeDynamicNodeProviderNames() +105
   MvcSiteMapProvider.DI.SiteMapNodeFactoryContainer.ResolveDynamicNodeProviders() +148
   MvcSiteMapProvider.DI.SiteMapNodeFactoryContainer..ctor(ConfigurationSettings settings, IMvcContextFactory mvcContextFactory, IUrlPath urlPath) +306
   MvcSiteMapProvider.DI.SiteMapLoaderContainer..ctor(ConfigurationSettings settings) +409
   MvcSiteMapProvider.DI.Composer.Compose() +430

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +229
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +193
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +35
   WebActivatorEx.BaseActivationMethodAttribute.InvokeMethod() +341
   WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +854
   WebActivatorEx.ActivationManager.RunPostStartMethods() +40
   WebActivatorEx.StartMethodCallingModule.Init(HttpApplication context) +159
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +530
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601



--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929 

我已经对此错误进行了搜索,我发现的错误显示了一个完全不同的调用堆栈跟踪。

这是MVC.SiteMap

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0"
            xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0 MvcSiteMapSchema.xsd">

  <mvcSiteMapNode title="Projects" controller="Project" action="Index">
      <mvcSiteMapNode title="Supplier/Trade" controller="SupplierTrade" action="Index"  preservedRouteParameters="pid">
          <mvcSiteMapNode title="Approval Actions" controller="SupplierTrade" action="ApprovalActions"  preservedRouteParameters="pid, stmid">
              <mvcSiteMapNode title="Edit PMs" controller="User" action="Index"  preservedRouteParameters="pid, stmid"/>
              <mvcSiteMapNode title="Contractor Standard Invoice Percent" controller="ContractorStandardInvoicePercent" action="Index"  preservedRouteParameters="pid, stmid"/>
              <mvcSiteMapNode title="Approval Status Of CostCode" controller="ApprovalStatusOfCostCode" action="Index"  preservedRouteParameters="pid, stmid"/>
          </mvcSiteMapNode>
      </mvcSiteMapNode>
  </mvcSiteMapNode>
</mvcSiteMap>

我一直认为我缺少一些配置设置或者我的开发机器上的文件,但生产机器上没有,因为版本3.3.6完美无瑕。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

错误表明MvcSiteMapProvider扫描项目中的[MvcSiteMapNodeAttribute]节点时出错。你可以尝试一些事情:

  1. 如果您未在应用程序中使用[MvcSiteMapNodeAttribute],则可以通过在web.config中将“MvcSiteMapProvider_ScanAssembliesForSiteMapNodes”设置为“false”来禁用此扫描。
  2. 如果您正在使用[MvcSiteMapNodeAttribute],请确保在“MvcSiteMapProvider_IncludeAssembliesForScan”中添加您在其中定义的所有程序集,并以逗号分隔。确保每个名称与“应用程序”选项卡上项目属性中“程序集名称”字段中定义的名称相匹配。当“MvcSiteMapProvider_ScanAssembliesForSiteMapNodes”为“true”时,此(或“MvcSiteMapProvider_ExcludeAssembliesForScan”)字段是必需的。
  3. 如果您使用的是“MvcSiteMapProvider_ExcludeAssembliesForScan”,请尝试切换到使用“MvcSiteMapProvider_IncludeAssembliesForScan”以确保MvcSiteMapProvider没有拾取一些它不应该使用的程序集。
  4. 参考:Configuring MvcSiteMapProvider