简体   繁体   中英

Unit testing error, could not load file or assembly

I have unit tests for my controllers (around 36). When I run them. I get same error for all the tests

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).

Here is my assemblyinfo class

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")]

It took me a while to track this issue down. The problem was that my test project implicitly referenced a class in another project that wasn't referenced explicitly in my test project. As soon as I added the reference (to the implicitly referenced project) to my test project, and rebuilt, the tests started populating in the Test Explorer again. The link @wal posted was the hint that got me thinking in that direction. From the post it seems this is a Visual Studio / Rhino Mocks issue.

when using generics and/or delegation, make sure all types implicitly referenced by your code are explicitly referenced in the project References.

Source: C# Compiler Bug, or just something obscure and frustrating? [alt]

My organization was using delay signing for their assemblies, which prevents the test runner from verifying the strong name of the DLLs.

Please check here for the solution

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM