After migrating a solution from MVC 1.0.0.0 Visual Studio 2008 to MVC 2.0.0.0 Visual Studio 2010 I get the following error:
The controller factory type 'MyLib.MyControllerFactory' must implement the IControllerFactory interface.
Parameter name: controllerFactoryType
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.ArgumentException: The controller factory type 'MyLib.MyControllerFactory' must implement the IControllerFactory interface.
Parameter name: controllerFactoryType
Source Error:
Line 35: protected void Application_Start()
Line 36: {
... container initialization ...
Line 38: ControllerBuilder.Current.SetControllerFactory(typeof(MyControllerFactory));
MyLib is an external shared library implemented in MVC 1.0.0.0
Here’s workaround I’ve found to make work my MVC 1.0.0.0 dependency under my MVC 2.0 website migrated to Visual Studio 2010.
In the Application_start in Global.asax I just instantiated the IControllerFactory using the implementation class MyControllerFactory instead of trying to get its type:
With that error fixed, then I got another crash:
This was produced because the legacy MVC 1.0 library wasn’t able to resolve MVC the reference to the interface in MVC 2.0 library loaded in the application.
I solved this by adding the following section in the config file to add assembly binding from System.Web.Mvc 1.0.0.0 to System.Web.Mvc 2.0.0.0:
<runtime><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<!-- Binding to help Common library MVC 1 code find the classes in MVC 2 -->
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
I also had to add this configuration block to the app.config file in my unit tests project to fix the broken tests.