2014-02-05 19 views
2

我正在使用MVCSiteMapProvider 4.4.9.0编写MVC 4.5应用程序。在运行Visual Studio Development Server的Visual Studio中开发时,一切都按预期工作。但是,将项目发布到生产服务器后,我遇到了NullReferenceException。这是调用堆栈。 (对不起,没有足够的信誉分发布的屏幕截图)MVCSiteMapProvider在移至产品时给出空引用

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作品上完美无缺。有任何想法吗?

+0

我得到了同样的错误,你有没有发现是什么造成的? –

回答

2

错误表明MvcSiteMapProvider扫描[MvcSiteMapNodeAttribute]节点的项目时出现错误。有些东西你可以尝试:

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

参考:Configuring MvcSiteMapProvider

+0

关闭MvcSiteMapProvider_ScanAssembliesForSiteMapNodes为我工作,但它很奇怪,因为这是在其他环境中工作。这对于我们部署到特定的Azure虚拟机时只是一个问题 –

+0

听起来这可能是由于Azure中的.NET反射安全权限问题导致的。 – NightOwl888

+0

感谢您的响应NightOwl - 最终证明.net框架没有正确注册到IIS上的框 –