I am getting the following exception:
No parameterless constructor defined for this 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.MissingMethodException: No parameterless constructor defined for this object.
when the framework attempts to construct controllers that do not derive from ApiController, such as my simple HomeController below:
public class HomeController : Controller
{
private IUnityContainer _unityContainer;
public HomeController(IUnityContainer unityContainer)
{
_unityContainer = unityContainer;
}
public ActionResult Index()
{
return View();
}
}
I have the following Boostrapper.cs class defined:
public static class Boostrapper
{
public static void Initialize()
{
var container = BuildUnityContainer();
GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);
}
private static IUnityContainer BuildUnityContainer()
{
var container = new UnityContainer();
RegisterTypes(container);
return container;
}
}
and Bootstrapper.Initialize() is the last line of code executed within Application_Start of Global.asax.cs?
Exception is not thrown on controller classes that derive from ApiController. Could someone please advise on what I am missing?
Thanks.