将解决方案从MVC 1.0.0.0 Visual Studio 2008迁移到MVC 2.0.0.0后出现错误Visual Studio 2010(IControllerFactory)

问题描述:

将解决方案从MVC 1.0.0.0 Visual Studio 2008迁移到MVC 2.0.0.0 Visual Studio 2010后,以下错误:将解决方案从MVC 1.0.0.0 Visual Studio 2008迁移到MVC 2.0.0.0后出现错误Visual Studio 2010(IControllerFactory)

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中是MVC实现的外部共享库1.0.0.0

这里的解决办法,我发现,使我的下MVC 2.0网站迁移到Visual Studio 2010中

在Application_Start在Global.asax中我只是用实现类实例化的IControllerFactory工作我的MVC 1.0.0.0依赖MyControllerFactory而不是试图获取其类型:

ControllerBuilder.Current.SetControllerFactory((IControllerFactory) new MyControllerFactory()); 

与该错误固定,然后我得到了另一个崩溃:

<b>Entry point was not found. </b> 
<b>Description:</b> 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. 

<b>Exception Details:</b> System.EntryPointNotFoundException: Entry point was not found. 

<b>Source Error: </b> 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

<b>Stack Trace: </b> 
[EntryPointNotFoundException: Entry point was not found.] System.Web.Mvc.IControllerFactory.CreateController(RequestContext requestContext, String controllerName) +0 System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +181 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +85 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +392 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +263

这是因为传统MVC 1.0库无法解析MVC对应用程序中加载的MVC 2.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>

我也:

我通过在配置文件中添加以下部分来添加组件从System.Web.Mvc 1.0.0.0到System.Web.Mvc 2.0.0.0结合解决了这个必须将此配置块添加到我的单元测试项目中的app.config文件以修复损坏的测试。

MyLib is an external shared library implemented in MVC 1.0.0.0

你将不得不重新编译(如果哟你有源代码),或者要求库的作者为你提供一个针对System.Web.Mvc 2.0.0.0编译的版本,否则这将不起作用。

+0

嗨,谢谢你的帮助。我找到了一种方法使其工作,但不能发布答案(网站限制8小时)。它需要在global.asax和运行时配置设置中将MVC 1.0.0.0映射到MVC 2.0.0.0。我明天会发布。 –

+0

图书馆的重新编译也不是一个好的选择,因为它在其他团队拥有的多个项目中共享。 –