2

I am trying to understand how the Html Helpers are built inside MVC 3. So i downloaded MVC 3 source and added as another project in same solution to debug it.

I followed this steps.

  1. Removed System.web.Mvc reference from my MVC Application

  2. Added a System.web.Mvc Source code project reference for debugging.

  3. In Web.config System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 to System.Web.Mvc

However i have other NInject(NInject, NInject.web.common, WebActivator, Microsoft.web.infrastructure) references added in my MVC 3 application for dependency injection.

Now i am getting an error in System.Web.MVC Source saying 'An error occurred when trying to create a controller of type 'MVCApp.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor. in below MVC Source code of

public IController Create(RequestContext requestContext, Type controllerType) 
{
    try
    {
        return (IController)(_resolverThunk().GetService(controllerType)
            ?? Activator.CreateInstance(controllerType));
    }
    catch (Exception ex) 
    {
        throw new InvalidOperationException(
            String.Format(CultureInfo.CurrentCulture,
                MvcResources.DefaultControllerFactory_ErrorCreatingController, controllerType),
                ex);
    }
}

Checking DependencyResolver.Current property says DependencyResolver.Current The type 'System.Web.Mvc.DependencyResolver' exists in both 'System.Web.Mvc.dll' and 'System.Web.Mvc.dll'

What more needs to be done in order to debug my MVC3App with MVC3 source code? how can i avoid this error?

Cristian Lupascu
  • 39,078
  • 16
  • 100
  • 137
Murali Murugesan
  • 22,423
  • 17
  • 73
  • 120

1 Answers1

1

Take a look on this solution: Ninject + MVC3 is not injecting into controller

Add this to the Web.config

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0" newVersion="4.0.0.0" />
    <bindingRedirect oldVersion="2.0.0.0" newVersion="4.0.0.0" />
    <!-- The following line was missing -->
    <bindingRedirect oldVersion="3.0.0.0" newVersion="4.0.0.0" /> 
  </dependentAssembly>

It solved this problem:

Checking DependencyResolver.Current property says DependencyResolver.Current The type 'System.Web.Mvc.DependencyResolver' exists in both 'System.Web.Mvc.dll' and 'System.Web.Mvc.dll'

Cheers.

Community
  • 1
  • 1
vtortola
  • 34,709
  • 29
  • 161
  • 263