Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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")]
like image 792
Cybercop Avatar asked Aug 21 '13 11:08

Cybercop


People also ask

Can not load file or assembly?

Http 5.2. 0.0? In summary if you get the "Could not load file or assembly error", this means that either your projects or their references were built with a reference to a specific version of an assembly which is missing from your bin directory or GAC.

Could not load file or assembly VS 2019?

Restart Visual Studio, clean and build a solution. Remove the class library references and add it again. Tools > Import and Export Settings Wizard > Reset all settings (maybe some setting was not well configured).


1 Answers

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]

like image 57
MoMo Avatar answered Oct 06 '22 20:10

MoMo