UPDATE - Please look at my answer for a link and explanation of the solution to this problem
Before we start, I know this is a very common quest
I was pulling my hair out on this for several hours on a recent project that I moved from MVC 3 to MVC 4. With the lack of on point answers I figured it had to be something I did as it appears that the Ninject.MVC3 nuget package will work fine with MVC 4 - and indeed it does.
In my case I wasn't fully upgrading the MVC3 project. After following this guide I got things to work as expected. My guess was that I was missing an assembly binding redirect.
So if you're upgrading an MVC 3 project to MVC 4, using Ninject and getting the no parameterless constructor defined error, hope this helps.
I got the same error message after getting the MVC3 from NuGet.
I don't know if you got your project setup the same way as I do but my web.config
is auto generated depending on environment. The MVC from NuGet is adding rows (<runtime>)
to the web.config
and those rows were removed since my merging config-files wasn't setup correctly.
Regards,
Kim
I have the same problem and the only thing that works for me is to change the "Local IIS Web server" in the Web project properties to "Use Visual Studio Development Server".
I don't know why but when I do this, my break point in NinjectWebCommon is hited. Like @Alex said, it's something with Visual Studio 2012 not enough bright to execute the code in NinjectWebCommon each time you build your application. It's also possible that it's me not enough bright to understand how it works under the hood.
I don't like my solution because I would prefer to use my Local IIS Web Server but for the moment, I have an application to create and to much time took with this $%?!!/ bug..feature..not sure.
Here is a dirty solution! Put this
var type = typeof(Ninject.Web.Mvc.MvcModule);
in the beginning of the AppStart event (or anywhere else )
Now let me explain what it means if someone didn't get trick yet. Thing is our http application class could reside anywhere in solution. Not only in web application. And this is very important because asp.net compilation routine is different from usual library applications. It eagerly loads ALL referenced libraries via BuildManager helper, while usually clr doesn't load types from start unless they're directly used.
Now let's get back to our situation: Ninject.Web.Mvc work as dynamic plugin, which doesn't require any mention within a code. And thus is not loaded if it was referenced inside Class library which leads to broken Mvc.Dependancy initialization.
This was solved for me by adding a reference via Nuget to Ninject.Web.MVC.
I was able to resolve this issue in an MVC5 web project by removing an #if #endif directive from my controllers constructor.