System.InvalidOperationException: Multiple types were found that match the controller named 'Home'. 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 'Home' has found the following matching controllers: SitecoreMVC.Areas.Site1.Controllers.HomeController SitecoreMVC.Areas.Site2.Controllers.HomeController
Above is the error which I get using MVCAreas as well, I've extended the Controller Rendering template and added two more fields which are Area and Namespace and during initialize route i'm doing the AreaRegistration.RegisterAllAreas();
I've also extended the GetRendererProcessor with my custom processor and i get error at controllerrunner in execute method as complier is not able to resolve the correct controller, in the below code namespace and area is passed but still it throws error.
AreaControllerRenderer.cs
public class AreaControllerRenderer : Renderer
{
public string Action { get; set; }
public string Controller { get; set; }
public string Area { get; set; }
public string Namespaces { get; set; }
public override string CacheKey
{
get
{
return "areacontroller::" + Controller + "#" + Action + "#" + Area + "#" + Namespaces;
}
}
public override void Render(System.IO.TextWriter writer)
{
var controllerRunner = new AreaControllerRunner(Controller, Action, Area, Namespaces);
string value = controllerRunner.Execute();
if (string.IsNullOrEmpty(value))
{
return;
}
writer.Write(value);
}
public override string ToString()
{
return "Controller: {0}. Action: {1}. Area {2}. Namespaces {3}".FormatWith(new object[]
{
Controller,
Action,
Area,
Namespaces
});
}
}
Please help!!
I was able to Solve this issue using the Fully Qualified Name of the controller with Assembly name as below -
SitecoreMVC.Areas.Site1.Controllers.HomeController, SitecoreMVC
The Sitecore ControllerFactory
currently doesn't allow to have multiple controllers with the same name. You have to choose a different name for each controller or add the fullname of your controller (including the assembly) into your controller rendering:
SitecoreMVC.Areas.Site1.Controllers.HomeController, SitecoreMVC