I just upgraded to the MVC 3 preview that just came out today.
I did not have time to play around with the new features so I just installed it and kept working on my existing MVC 2 application. Later in the day when I ran my application I found that I was receiving the error
No parameterless constructor defined for this object.
* commence freaking out *
It appears that the install of MVC 3 Preview 1 has affected my existing MVC 2 application. Or so it seemed. Uninstalling MVC 3 Preview 1 fixes the problem. Installing it again causes the problem.
My MVC 2 application is using Ninject 2 so I can inject dependencies into my constructors and they do not require parameterless constructors. This made me think that it had to be a problem with Ninject, but all the proper breakpoints were being hit in my Ninject application to set the default controller factory.
I attempted to reproduce the problem in a simple project (since I was convinced it was Ninject). After uninstalling MVC 3, I created a simple application that required an interface to be injected into my HomeController using Ninject. I ran it to see that it works. Then I installed MVC 3 just as I did before but this time the sample application worked.
So what is the difference? More importantly, what is the solution?
It's all in your references. Looking side by side at my project files, I can see a difference. Here is the sample MVC 2 project that worked:
<Reference Include="System.Web.Mvc, Version=18.104.22.168, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
Here is the production MVC 2 application that did not work after installing MVC 3 Preview 1:
<Reference Include="System.Web.Mvc, Version=22.214.171.124, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <SpecificVersion>FalseSpecificVersion> </Reference>
The difference being SpecificVersion. The hint text reads: Specific Version Indicates whether this assembly can be resolved without regard to multi-targeting rules for assembly resolution.
So there you have it. My production application is looking for the latest System.Web.Mvc DLL it could find even though I have specified I want to use 126.96.36.199. By either defaulting this property or explicitly setting SpecificVersion to True will tell the application to use the version you tell it to.I do not believe this is any fault of MVC 3, MVC 2, Ninject, or anything else. This is just something to look out for when you get brave (as you should) and start looking at MVC 3 Preview 1.