MVCSiteMapProvider gives null reference when moved to production - nullreferenceexception

I am writing an MVC 4.5 application using MVCSiteMapProvider 4.4.9.0. When developing in Visual Studio running the Visual Studio Development Server, everything works as expected. However, after publishing the project to the production server, I am running into a NullReferenceException. Here is the call stack. (Sorry, not enough reputation points to post screen shot)
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
I have done a search on this error and the ones I have found showed a completely different call stack trace.
Here is the 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>
I keep thinking that there is some configuration setting I am missing or a file that is on my dev machine but not on the production machine as version 3.3.6 works flawlessly. Any ideas?

The error indicates there is something wrong when MvcSiteMapProvider scans your project for [MvcSiteMapNodeAttribute] nodes. Some things you could try:
If you are not using [MvcSiteMapNodeAttribute] in your application, you can disable this scanning by setting "MvcSiteMapProvider_ScanAssembliesForSiteMapNodes" to "false" in web.config.
If you are using [MvcSiteMapNodeAttribute], make sure you add all of the assemblies where you have them defined in "MvcSiteMapProvider_IncludeAssembliesForScan", separated by commas. Make sure each name matches what is defined in the "Assembly name" field in project properties on the Application tab. This (or the "MvcSiteMapProvider_ExcludeAssembliesForScan") field is required when "MvcSiteMapProvider_ScanAssembliesForSiteMapNodes" is "true".
If you are using "MvcSiteMapProvider_ExcludeAssembliesForScan", try switching to using "MvcSiteMapProvider_IncludeAssembliesForScan" to ensure MvcSiteMapProvider isn't picking up some assemblies that it shouldn't.
Reference: Configuring MvcSiteMapProvider

Related

Could not load file or assembly 'Microsoft.EnterpriseManagement.OperationsManager.Apm.DataCollecting.Producers.Mvc.4.0

We were running Windows Server 2008 R2 and upgraded to 2016 and since then our applications have stopped running. ASP.NET Web Forms is still working and only MVC seems to have stopped running.
They were all thrwoing HTTP 503 error and after repaiting IIS URL Rewrite Module 2, they have started throwing the following error:
Server Error in '/Mail' Application.
Could not load file or assembly 'Microsoft.EnterpriseManagement.OperationsManager.Apm.DataCollecting.Producers.Mvc.4.0, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
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.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EnterpriseManagement.OperationsManager.Apm.DataCollecting.Producers.Mvc.4.0, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
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.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.EnterpriseManagement.OperationsManager.Apm.DataCollecting.Producers.Mvc.4.0, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Stack Trace:
[FileNotFoundException: Could not load file or assembly 'Microsoft.EnterpriseManagement.OperationsManager.Apm.DataCollecting.Producers.Mvc.4.0, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +0
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +194
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +80
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +70
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +18
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +444
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +157
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2106.0
I managed to solve by doing two things:
Repairing the IIS URL Rewrite Module
Uninstalling Microsoft Monitoring Agent which contains the assembly that MVC application is complaining about.

What may cause OWIN to intermittently fail to load?

Recently some unusual errors have started appearing on our development server. We are using Jenkins to build and deploy an ASP.NET Web API that uses OWIN and up until now everything has been working correctly. However, recently we have started to intermittently see errors like the following, lightly redacted error from the Windows Event Log:
Exception information:
Exception type: EntryPointNotFoundException
Exception message: The following errors occurred while attempting to load the app.
- No assembly found containing an OwinStartupAttribute.
- The given type or method 'Api.Startup' was not found. Try specifying the Assembly.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.
at Microsoft.Owin.Host.SystemWeb.OwinBuilder.GetAppStartup()
at Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint()
at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
at Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context)
at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)
at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context)
at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context)
at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)
Recycling the IIS application pool generally resolves the problem but the fact it is happening is concerning. Any ideas as to what might be causing this to happen?

Asp.net Webapi CORS with Thinktecture.IdentityModel

I am looking into resolviong Asp.net Webapi CORS issue with Thinktecture.Identitymodel as described in this URL
http://brockallen.com/2012/06/28/cors-support-in-webapi-mvc-and-iis-with-thinktecture-identitymodel/
I am using VS2012 with .Net 4.5
I am coming across a couple of problems here:
1) This is the error I am coming across when i make a request
Attempted to access an element as a type incompatible with the array
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.
System.ArrayTypeMismatchException: Attempted to access an element as a
type incompatible with the array.
[ArrayTypeMismatchException: Attempted to access an element as a type
incompatible with the array.]
System.Collections.Generic.List`1.Insert(Int32 index, T item) +62
Galaxy.CorsConfig.RegisterCors(HttpConfiguration config) +99
Galaxy.WebApiApplication.Application_Start() +377
[HttpException (0x80004005): Attempted to access an element as a type
incompatible with the array.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext
context, HttpApplication app) +12864673
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr
appContext, HttpContext context, MethodInfo[] handlers) +175
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): Attempted to access an element as a type
incompatible with the array.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)
+159 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest
wr, HttpContext context) +12722601
My application pool is pointing to Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
2)My second question is after doing things as mentioned in WebApi. Do i still need to add HTTPmodule for IIS?
Its should be very easy to get going with this. I don't know what I am missing here.
Any pointers are highly appreciated.
Thanks.
I had a very similar issue because Thinktecture.IdentityModel.Web 1.4 pulled in HttpClient 0.6, which references System.Net.Http* v2.0 assemblies, but the HttpHanders list in MVC needs 4.0. Once I removed the Web pkg and its dependencies, things went back to working.
I figured out that I had a version mismatch of assemblies . My actual project was in .Net 4.0 and Thinktecture was in .Net 4.5 .
Once i fixed that it worked.
Similar to Ben's solution above, this problem occurred for me with v3.5.0 of Thinktecture.IdentityModel because of an old version of System.Net.Http (2.2.13.0) referenced in my web.config and installed in the bin folder.
Removing the dependentAssembly binding from my web.config and deleting the old System.Net.Http .dll solved the problem.
This was for a .NET 4.5 project.

Cannot Deploy MVC 3 Project with Entity Framework 4.3.1 and Oracle ODAC

I'm currently trying to deploy a MVC 3 application I've been working on to our test web server, and am running into a major problem with loading everything correctly. To try and give as much info about this as possible, I'm doing a bin deploy (I've sent all references to copy locally), and am doing a basic Publish on the web project via file system to the application directory on the server. The components I'm using are:
Entity Framework 4.3.1
Oracle ODAC 11.2.0 (version 4.112.3.0)
This application has 2 Entity Framework objects, one going to a SQL Server database and the other going to an Oracle 10g database. I believe the issue is with the Entity Framework object going to the Oracle database. This is my first MVC 3 project and my first deployment (there's a lot of "new" variables here), so I'm not sure if I'm missing anything or not. How do I fix this issue? Everything works perfectly fine on my local machine, it's only when I deploy the project to the server, that I have problems.
Things I've tried so far:
All of my controllers inherit from a base controller (BaseController), where the instances of the entity framework objects live. I cannot get to the Index view of any controller that inherits from the BaseController, but the HomeController inherits from Controller. This page works correctly. I've tried inheriting from Controller in the others, and that allows me to get to the Index view, but going back to BaseController causes the errors in the stack trace again. The error appears to happen on the line where I'm declaring my entity framework object going to the oracle database:
protected internal RadixWebDataPRDX dbRadixData = new RadixWebDataPRDX();
I have the Oracle.DataAccess.dll being copied over, and this still causes an issue.
My stack trace for this error is below, thanks:
Server Error in '/RadixMVC' Application.
Unable to find the requested .Net Framework Data Provider. It may not be installed.
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.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.
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:
[ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.]
System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1420503
System.Data.EntityClient.EntityConnection.GetFactory(String providerString) +34
[ArgumentException: The specified store provider cannot be found in the configuration, or is not valid.]
System.Data.EntityClient.EntityConnection.GetFactory(String providerString) +63
System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) +483
System.Data.EntityClient.EntityConnection..ctor(String connectionString) +77
System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString) +40
System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) +17
RadixMVC.Models.Data.RadixWebDataPRDX..ctor() in C:\Users\862599\Documents\Visual Studio 2010\Projects\RadixMVC\RadixMVC\RadixMVC.Models.Data\RadixDataPRDX.Designer.cs:34
RadixMVC.Controllers.BaseController..ctor() in C:\Users\862599\Documents\Visual Studio 2010\Projects\RadixMVC\RadixMVC\RadixMVC\Controllers\BaseController.cs:17
RadixMVC.Controllers.AccountsPayableController..ctor() +29
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +67
[InvalidOperationException: An error occurred when trying to create a controller of type 'RadixMVC.Controllers.AccountsPayableController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +181
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +77
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +66
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +209
System.Web.Mvc.<>c__DisplayClass6.<BeginProcessRequest>b__2() +50
System.Web.Mvc.<>c__DisplayClassb`1.<ProcessInApplicationTrust>b__a() +13
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Func`1 func) +124
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +98
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8970356
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
The solution to this was what Bob said. The ODAC components had to be installed on the server as well (something I was unaware of). Thanks Bob!

Error after migrating a solution from MVC 1.0.0.0 Visual Studio 2008 to MVC 2.0.0.0 Visual Studio 2010 (IControllerFactory )

After migrating a solution from MVC 1.0.0.0 Visual Studio 2008 to MVC 2.0.0.0 Visual Studio 2010 I get the following error:
The controller factory type 'MyLib.MyControllerFactory' must implement the IControllerFactory interface.
Parameter name: controllerFactoryType
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.ArgumentException: The controller factory type 'MyLib.MyControllerFactory' must implement the IControllerFactory interface.
Parameter name: controllerFactoryType
Source Error:
Line 35: protected void Application_Start()
Line 36: {
... container initialization ...
Line 38: ControllerBuilder.Current.SetControllerFactory(typeof(MyControllerFactory));
MyLib is an external shared library implemented in MVC 1.0.0.0
MyLib is an external shared library implemented in MVC 1.0.0.0
You will have to recompile (if you have the source code) or ask the author of the library to provide you a version compiled against System.Web.Mvc Version 2.0.0.0 or this won't work.
Here's workaround I've found to make work my MVC 1.0.0.0 dependency under my MVC 2.0 website migrated to Visual Studio 2010.
In the Application_start in Global.asax I just instantiated the IControllerFactory using the implementation class MyControllerFactory instead of trying to get its type:
ControllerBuilder.Current.SetControllerFactory((IControllerFactory) new MyControllerFactory());
With that error fixed, then I got another crash:
<b>Entry point was not found. </b>
<b>Description:</b> 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.
<b>Exception Details:</b> System.EntryPointNotFoundException: Entry point was not found.
<b>Source Error: </b>
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.
<b>Stack Trace: </b>
[EntryPointNotFoundException: Entry point was not found.] System.Web.Mvc.IControllerFactory.CreateController(RequestContext requestContext, String controllerName) +0
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +181
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +85
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +392
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +263
This was produced because the legacy MVC 1.0 library wasn't able to resolve MVC the reference to the interface in MVC 2.0 library loaded in the application.
I solved this by adding the following section in the config file to add assembly binding from System.Web.Mvc 1.0.0.0 to System.Web.Mvc 2.0.0.0:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<!-- Binding to help Common library MVC 1 code find the classes in MVC 2 -->
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
I also had to add this configuration block to the app.config file in my unit tests project to fix the broken tests.

Resources