violates the constraint of type parameter 'T'

编写单元测试时,新增一个控制器的抽象类。如下定义:

1 [TestClass]
2 public abstract class TestControllerBase<T> : TestBase where T : Controller

编写一个HomeController的单元测试:

1 [TestClass]
2 public class TestHomeController : TestControllerBase<HomeController>

编译通过,但Test的Output窗口提示:System.TypeLoadException was unhandled Message="GenericArguments[0], "TestControllerBase`1[T]' violates the constraint of type parameter 'T'."。后来发现HomeController引用的System.Web.Mvc.dll版本号为3.0.0.0,而单元测试项目却是4.0.0.0。

posted @ 2012-08-13 23:17  junchu25  阅读(727)  评论(0编辑  收藏  举报