C# 单元测试错误,无法加载文件或程序集
我对我的控制器进行了单元测试(大约36个)。当我运行它们时。我在所有的测试中都得到了相同的错误C# 单元测试错误,无法加载文件或程序集,c#,asp.net-mvc,unit-testing,asp.net-mvc-4,C#,Asp.net Mvc,Unit Testing,Asp.net Mvc 4,我对我的控制器进行了单元测试(大约36个)。当我运行它们时。我在所有的测试中都得到了相同的错误 Unable to get type AdminPortal.Tests.Controller_Test.OwnedModuleControllerTest. Error: System.IO.FileLoadException: Could not load file or assembly 'AdminPortal.Tests, Version=1.0.0.0, Culture=neutral,
Unable to get type AdminPortal.Tests.Controller_Test.OwnedModuleControllerTest. Error: System.IO.FileLoadException: Could not load file or assembly 'AdminPortal.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Signature missing argument. (Exception from HRESULT: 0x801312E3)
File name: 'AdminPortal.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' ---> System.Runtime.InteropServices.COMException (0x801312E3): Signature missing argument. (Exception from HRESULT: 0x801312E3)
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Microsoft.VisualStudio.TestPlatform.MSTestFramework.TypeCache.LoadType(String typeName, String assemblyName).
这是我的组装信息课程
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AdminPortal.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AdminPortal.Tests")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("0412bc0c-30bc-4e0c-9a8d-bcbcd7876702")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
我花了一段时间才找到这个问题。问题是,我的测试项目隐式引用了另一个项目中的类,而该类在我的测试项目中没有显式引用。当我将引用(隐式引用的项目)添加到我的测试项目并重新构建后,测试就开始在测试资源管理器中再次填充。@wal发布的链接就是让我朝这个方向思考的暗示。从帖子上看,这似乎是一个VisualStudio/Rhino模拟的问题 使用泛型和/或委托时,请确保在项目引用中显式引用代码隐式引用的所有类型
来源:这些测试是在本地还是在服务器上失败?是否有一个特定的环境,他们在服务器上工作。他们之前通过了考试,但突然出现了错误,说考试没有结果。后来我意识到这是重拾器的问题,于是我解决了它。现在它们只是不运行并给出前面提到的错误。运行时(.NET)和环境(visualstudio)的版本在本地是否与服务器上的版本相同?您的本地环境和服务器之间似乎存在版本不匹配的问题。请参阅使用泛型和/或委派时的
,确保代码隐式引用的所有类型都在项目引用中显式引用
,我想另一件要注意的事情是,如果服务器上安装了多个版本,则生成脚本将针对正确的版本(如上所述)执行。这对我来说也是触发的。只是为了让其他人找到解决方案:我在测试项目的app.config
中添加了引用