简体   繁体   English

无法在单元测试中加载文件或程序集'System.Web.Mvc

[英]Could not load file or assembly 'System.Web.Mvc In Unit Test

I have unit tests and inside them I call a method that eventually calls this line: 我有单元测试,在其中,我调用了一个最终调用此行的方法:

DataSourceResult response = lstshiftGroup.ToDataSourceResult(request);

Which throws this exception: 引发此异常:

Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. 无法加载文件或程序集'System.Web.Mvc,版本= 3.0.0.0,区域性=中性,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一。 The system cannot find the file specified. 该系统找不到指定的文件。

In my test project I have reference of System.Web.Mvc, Version=4.0.0.0 and in my project I have the same assembly. 在我的测试项目中,我引用了System.Web.Mvc,版本= 4.0.0.0,在我的项目中,我具有相同的程序集。

What is wrong with my test? 我的考试出了什么问题?

You need to add reference to Asp.Net MVC to your Unit Test project. 您需要在单元测试项目中添加对Asp.Net MVC的引用。 You can do this with NuGet. 您可以使用NuGet做到这一点。 Here is the link to NuGet for MVC. 这是指向NuGet for MVC的链接。 Follow the instructions there to install it into your Unit Test project: https://www.nuget.org/packages/aspnetmvc 按照那里的说明将其安装到单元测试项目中: https : //www.nuget.org/packages/aspnetmvc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在MVC 5中加载文件或程序集'System.Web.Mvc' - Could not load file or assembly 'System.Web.Mvc' in mvc 5 无法加载文件或程序集“ System.Web.MVC,版本4.0.0.0” - could not load file or assembly 'System.Web.MVC, version 4.0.0.0,' 无法加载文件或程序集System.Web.Mvc,版本= 5.2.3.0 - Could not load file or assembly System.Web.Mvc, Version=5.2.3.0 无法加载文件或程序集System.Web.Mvc - Could not load file or assembly System.Web.Mvc 尝试使用端点时无法加载文件或程序集System.Web.Mvc - Could not load file or assembly System.Web.Mvc when trying to use endpoint 调用API服务时无法加载文件或程序集'System.Web.Mvc' - Could not load file or assembly 'System.Web.Mvc' when calling an API service 使用Autofac获取错误“无法加载文件或程序集'system.web.mvc版本= 5.1.0.0” - Using Autofac get error “could not load file or assembly 'system.web.mvc version=5.1.0.0” 无法加载文件或程序集'System.Web.Mvc(1)'或其依赖项之一 - Could not load file or assembly 'System.Web.Mvc(1)' or one of its dependencies 无法加载文件或程序集 System.Web.Mvc 或其依赖项之一 - Could not load file or assembly System.Web.Mvc or one of its dependencies 无法在“新”框中加载文件或程序集'System.Web.Mvc,版本= 3.0.0.0 - Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0 on NEW box
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM