The IControllerFactory 'MvcSiteMapProvider.DI.ControllerFactoryDecorator' did not return a controller for the name 'Scripts'

StackOverflow https://stackoverflow.com/questions/18507107

Domanda

I have an MVC 4 project and have just upgraded to SiteMapProvider v4.0.17; since the upgrade I am getting an error on the post back of any changes on the edit forms; the menu itself works as expected, and nothing else was changed in the project. The error is: -

The IControllerFactory 'MvcSiteMapProvider.DI.ControllerFactoryDecorator' did not return a controller for the name 'Scripts'

The only 'Scripts' in the project is the folder containing the .js files, so I'm not sure where to start looking;. The exception happens at: -

>   System.Web.Mvc.dll!System.Web.Mvc.MvcHandler.ProcessRequestInit(System.Web.HttpContextBase httpContext, out System.Web.Mvc.IController controller, out System.Web.Mvc.IControllerFactory factory) + 0x159 bytes 
System.Web.Mvc.dll!System.Web.Mvc.MvcHandler.BeginProcessRequest(System.Web.HttpContextBase httpContext, System.AsyncCallback callback, object state) + 0x32 bytes  
System.Web.Mvc.dll!System.Web.Mvc.MvcHandler.BeginProcessRequest(System.Web.HttpContext httpContext, System.AsyncCallback callback, object state) + 0x33 bytes  
System.Web.Mvc.dll!System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object extraData) + 0x11 bytes   
System.Web.dll!System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() + 0x227 bytes    
System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step, ref bool completedSynchronously) + 0x9c bytes 
System.Web.dll!System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(System.Exception error) + 0x1a7 bytes  
System.Web.dll!System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object extraData) + 0xf8 bytes  
System.Web.dll!System.Web.HttpRuntime.ProcessRequestInternal(System.Web.HttpWorkerRequest wr) + 0x284 bytes 
System.Web.dll!System.Web.HttpRuntime.ProcessRequestNoDemand(System.Web.HttpWorkerRequest wr) + 0x6e bytes  
System.Web.dll!System.Web.HttpRuntime.ProcessRequest(System.Web.HttpWorkerRequest wr) + 0x47 bytes  
WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Request.Process() + 0x188 bytes 
WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Microsoft.VisualStudio.WebHost.Connection conn) + 0x66 bytes    
[Appdomain Transition]  
WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Server.OnSocketAccept(object acceptedSocket) + 0xa1 bytes   
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state) + 0x3e bytes 
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0xa7 bytes  
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x16 bytes  
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() + 0x60 bytes 
mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() + 0x149 bytes  
mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() + 0x5 bytes 
[Native to Managed Transition]  

Could anyone help me with where to look for the issue?

Thanks

È stato utile?

Soluzione

The internal DI container uses a decorator pattern on whatever IControllerFactory you have registered with MVC. In all cases except when you are calling the /sitemap.xml endpoint, this class simply calls your registered IControllerFactory. If you have a custom one, you should be able to set a breakpoint in the CreateController method to find out why your IControllerFactory is not returning the controller in this case.

If you are not using a custom IControllerFactory, I would venture to guess this has something to do with your routes being misconfigured in a way that it is checking for a non-existent controller named Scripts. You probably need to add a line similar to this near the top of the RouteConfig.cs file to force MVC not to consider this case when resolving your controllers.

routes.IgnoreRoute("Scripts/{*pathInfo}");

If that doesn't work, I would suggest opening an issue at GitHub, as this will probably require some back and fourth communication to resolve. It would go a long way to finding a solution if you could build a demo project that exhibits the problem and either post it at GitHub or zip it and make it available for download.

Altri suggerimenti

To expatiate @NightOwl888's answer, this works for me routes.IgnoreRoute("Scripts/{*pathInfo}");

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top