views:

49

answers:

3

When I run the Release build of my (VS 2008 .NET) unit tests, I get the following exception:

System.IO.FileLoadException: Could not load file or assembly 'arcVegaORM,
Version=1.0.3856.24327, Culture=neutral, PublicKeyToken=0dd85ae1d99ddbee' 
or one of its dependencies. The located assembly's manifest definition does
not match the assembly reference. (Exception from HRESULT: 0x80131040).

I do not get the exception when I run the debug build tests.

The unit test framework is copying an old version of the 'arcVegaORM' assembly into the TestResults\Out folder. I do not know where it gets the old version from - it does not match the version in the projects bin\Release folder.

I am beginning to think there is a bug with the VS.NET unit test framework, and that it has the old version cached.

Has anyone else experienced these problems?

+2  A: 

One thing to check would be the GAC (global assembly cache). You can do that by opening windows explorer and typing in c:\windows\assembly in the address bar (assuming your OS is installed on the c drive).

It may be getting the assembly from the GAC instead.

Other things to do would be to clean the solution and do a rebuild all to make sure you don't have any old assembly references.

Also, if this is a web application, it always helps to stop IIS and then go clean out the C:\WINDOWS\Microsoft.NET\Framework\framework_version\Temporary ASP.NET Files folder.

TIP
The other thing to use is the .Net reflector. You can see what dependencies the assembly has, and you need to make sure they are all present on the target machine.

The way to do this is to install the reflector, then run it, then drag your assembly into it and you can see the assembly's dependencies. You need to make sure every one of those dependency dll's is available on the target machine, and also, the version number must be correct if they are signed assemblies.

TIP2
Note that sometimes you get issues where assembly A is bound against version xxx of assembly B, and assembly C is bound against version yyy of assembly B. In other words, 2 different assemblies in your project are bound against different versions of the same assembly. This is the modern day version of DLL Hell. The way to hack around this is to use assembly rebinding. You can read about it here.

dcp
The assembly is not in the GAC - I already checked. And the problem is reproducable on other machines.
GarethOwen
See my latest tip, I use this technique to resolved these types of problems. Also, I'm adding tip2 in a second, so be on the lookout :).
dcp
+1 for your detailed answer, but I don't think this is the problem. The assembly that cannot be found - arcVegaORM - is a project in my solution. Of coures I tried doing a full rebuild - but the version that is copied into the test run directory is not the same version as that in the arcVegaORM bin directory. Only a problem when running the Release tests - running the Debug build tests works fine!
GarethOwen
If it's a project in your solution, are you using a project reference or an assembly reference? If it's the latter, then maybe it's not getting the correct version, and it's usually best to use a project reference. One other thing to try would be recreating the solution and the projects (not sure how big of a task that would be) just to see if it makes a difference. I'm sorry for not being more helpful, that's about all I can think of.
dcp
I am using a project reference.I have now found a post on the MSDN Forums - could this a bug?http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/af530ba8-1299-4113-a5fe-4f6b009fa599
GarethOwen
Good find. Sure looks like a bug, too bad MS doesn't seem to be doing anything about it. I use NUnit primarily so haven't much experience with MS-Unit, although I think we are switching to MS-Unit at my shop soon. Maybe we should re-think that decision :).
dcp
!! If I turn off code coverage, then the tests run fine !!
GarethOwen
A: 

As per dcp - use Reflector to determine whether one (or more) of the project's reference assemblies in your project itself references an older version of arcVegaORM.

If you can, find and change that assembly to use the newer arcVegaORM.

Otherwise (if you can't change this reference assembly), you might need to consider GACing both versions of arcVegaORM.

nonnb
A: 

I have now found a post on the MSDN Forums - it seems to be a bug:

http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/af530ba8-1299-4113-a5fe-4f6b009fa599

!! If I turn off code coverage, then the tests run fine !!

GarethOwen