title: Simple Injector - No parameterless constructor defined for this object when resolving MVC controller
body: <p>I have a new MVC web project which I'm using MVC and Web API in. I have setup Simple Injector (version 2.5.2 from NuGet) using the following code in my global file</p>
  <pre><code>// Register Injectors
  SimpleInjectorConfig.Register();
  </code></pre>
  <p>In my SimpleInjectorConfig.cs file i have</p>
  <pre><code>public class SimpleInjectorConfig
  {
      public static void Register() {
          // Create the container as usual.
          Container container = new Container();
  
          // services
          container.Register&lt;IService, MyService&gt;();
  
          // data
          container.Register&lt;IRepository, MyRepository&gt;();
  
          // Register your types, for instance using the RegisterWebApiRequest
          // extension from the integration package:
          container.RegisterMvcControllers(
              System.Reflection.Assembly.GetExecutingAssembly());
  
          container.RegisterMvcAttributeFilterProvider();
  
          // This is an extension method from the integration package.
          container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
  
          // verify its all ok
          container.Verify();
  
          // add dependency
          GlobalConfiguration.Configuration.DependencyResolver = 
              new SimpleInjectorWebApiDependencyResolver(container);
      }
  }
  </code></pre>
  <p>Now I have 2 controllers, 1 is a Web API controller and 1 is a normal MVC controller.</p>
  <p>My Web API controller works fine and looks like this</p>
  <pre><code>public class MyApiController : ApiController
  {
      private IService _service;
  
      public MyApiController(IService service)
      {
          _service = service;
      }
  
      public IHttpActionResult Get(int id)
      {
          // I get my entity here and return it
          EntityObject myEntity = _service.Get(id);
          return Ok(myEntity);
      }
  }
  </code></pre>
  <p>As I said the above code works fine, I can execute the URL and it returns what I would expect.</p>
  <p>Now I have my MVC controller, that looks very similar to the above, here it is</p>
  <pre><code>public class MyController : Controller
  {
      private IService _service;
  
      public MyController(IService service)
      {
          _service = service;
      }
  
      public ActionResult Index()
      {
          return Search();
      }
  
      public ActionResult Search()
      {
          return View();
      }
  }
  </code></pre>
  <p>Now I can't understand at all why I keep getting the following error. I cannot add a public constructor as that causes an error with Simple Injector.</p>
  <blockquote>
  <p>System.MissingMethodException: No parameterless constructor defined for this object.</p>
  </blockquote>
  <pre><code>   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean&amp; canBeCached, RuntimeMethodHandleInternal&amp; ctor, Boolean&amp; bNeedSecurityCheck) +0
     System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark) +113
     System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark) +232
     System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
     System.Activator.CreateInstance(Type type) +66
     System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +110
  
  [InvalidOperationException: An error occurred when trying to create a controller of type 'my.project.Web.Controllers.MyController'. Make sure that the controller has a parameterless public constructor.]
     System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +247
     System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +438
     System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +257
     System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController&amp; controller, IControllerFactory&amp; factory) +328
     System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +157
     System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +88
     System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +50
     System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
     System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +155
  </code></pre>
  <p>If someone could point me in the right direction, that would be great.</p>