c# - 无法在单元测试中加载文件或程序集“System.Web.Mvc”

标签 c# .net asp.net-mvc asp.net-mvc-4 unit-testing

我有单元测试,在其中我调用了一个最终调用这一行的方法:

DataSourceResult response = lstshiftGroup.ToDataSourceResult(request);

抛出异常:

Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

在我的测试项目中,我引用了 System.Web.Mvc,Version=4.0.0.0,在我的项目中,我有相同的程序集。

我的测试有什么问题?

最佳答案

您需要将对 Asp.Net MVC 的引用添加到您的单元测试项目中。您可以使用 NuGet 执行此操作。这是指向 MVC 的 NuGet 的链接。按照那里的说明将其安装到您的单元测试项目中:https://www.nuget.org/packages/aspnetmvc

关于c# - 无法在单元测试中加载文件或程序集“System.Web.Mvc”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24885159/

相关文章:

C# 错误 : Use of unassigned local variable

c# - 方法参数 C# 中的有界泛型类型

c# - 如何在调用 Task.WaitAll 之前了解异常?

c# - 如何以编程方式重启 MVC4 项目

c# - MVC 存储库 - 域模型与实体模型

c# - Sharepoint 2010 客户端对象模型从 Url 获取列表项

c# - 如何测量页面时间负载?

javascript - Div 不显示/隐藏单选按钮选择

c# - DataGridView 只读 "bug"

c# - 从遗留 UUID 迁移到标准 UUID