I am running Commerce SXA (XP 9.0.2 + XC 9.0.3) with two sites next to eachother. One site is non-SXA and the other SXA based. I have a controller with the same name as exists in Commerce SXA: CartController
.
In my non-SXA based site I get the following stacktrace for MVC controller resolution:
Exception: System.InvalidOperationException
Message: Multiple types were found that match the controller named 'Cart'. This can happen if the route that services this request ('{*pathInfo}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.
The request for 'Cart' has found the following matching controllers:
Sitecore.Commerce.XA.Feature.Cart.Controllers.CartController
My.Feature.Checkout.Controllers.CartController
Source: System.Web.Mvc
at System.Web.Mvc.DefaultControllerFactory.GetControllerTypeWithinNamespaces(RouteBase route, String controllerName, HashSet`1 namespaces)
at System.Web.Mvc.DefaultControllerFactory.GetControllerType(RequestContext requestContext, String controllerName)
at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
at Sitecore.Mvc.Controllers.SitecoreControllerFactory.CreateController(RequestContext requestContext, String controllerName)
I solved this error by fully qualifying the controller name in the Rendering: My.Feature.Checkout.Controllers.CartController, My.Assembly
.
While in my SXA site I get the following stacktrace:
Exception: System.InvalidOperationException
Message: Multiple types were found that match the controller named 'cart'. This can happen if the route that services this request ('api/cxa/{controller}/{action}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.
The request for 'cart' has found the following matching controllers:
Sitecore.Commerce.XA.Feature.Cart.Controllers.CartController
My.Feature.Checkout.Controllers.CartController
Source: System.Web.Mvc
at System.Web.Mvc.DefaultControllerFactory.GetControllerTypeWithinNamespaces(RouteBase route, String controllerName, HashSet`1 namespaces)
at System.Web.Mvc.DefaultControllerFactory.GetControllerType(RequestContext requestContext, String controllerName)
at System.Web.Mvc.DefaultControllerFactory.System.Web.Mvc.IControllerFactory.GetControllerSessionBehavior(RequestContext requestContext, String controllerName)
at System.Web.Mvc.MvcRouteHandler.GetSessionStateBehavior(RequestContext requestContext)
at System.Web.Mvc.MvcRouteHandler.GetHttpHandler(RequestContext requestContext)
at Sitecore.Mvc.Routing.RouteHandlerWrapper.GetHttpHandler(RequestContext requestContext)
at System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
The second shows a different stacktrace, and fully qualifying (which does SXA by default) does not help.
Why is there a different stacktrace for non-SXA and SXA?
Is there another solution than using MVC areas for this?
BasketController
orCheckoutController
(base on functionality), and the problem should be gone.