Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
874 views
in Technique[技术] by (71.8m points)

.net - How do I investigate the course of a test's assembly refusing to load in NUnit?

(This works for other people in my team, so it is likely to be something to do with the setup of my machine.)

I am using the NUnit GUI test runner. When I use File/Open Project to load the test's assembly, I get an error.

The project was built with Visual Studio 2005 and Visual Studio’s About box gives the .NET framework version as 2.0.50727 SP2.

This is the error I get:

Assembly Not Loaded


System.BadImageFormatException : Could not load file or assembly 'Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format. You may be attempting to load an assembly built with a later version of the CLR than the version under which NUnit is currently running (2.0.50727) or trying to load a 64-bit assembly into a 32-bit process.


I have just used Assembly Binding Log Viewer (Fuslogvw.exe) to look at the fusions log, this is what is shows me, that does not make any sence, as I told it to look at all binds.

*** Assembly Binder Log Entry  (05/11/2010 @ 11:55:26) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:WindowsMicrosoft.NETFramework64v2.0.50727mscorwks.dll
Running under executable  C:Program Files (x86)NUnit 2.5.7in
et-2.0
unit.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = KSSRETAILian.ringrose
LOG: DisplayName = System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
 (Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/NUnit 2.5.7/bin/net-2.0/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = nunit.exe
Calling assembly : nunit-gui-runner, Version=2.5.7.10213, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:Program Files (x86)NUnit 2.5.7in
et-2.0
unit.exe.config
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFramework64v2.0.50727configmachine.config.
LOG: Post-policy reference: System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
LOG: Reusing an assembly instance that was previously loaded (C:WindowsassemblyGAC_MSILSystem.Windows.Forms2.0.0.0__b77a5c561934e089System.Windows.Forms.dll).

Thanks to Lasse pointing me in the right direction. When I run nunit-x86.exe, I can load the test DLL. Therefore there must be a 32-bit DLL somewhere in the system. However I still don't know how to get a useful set of logs to track down this type of problem in a logical way.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are a few reasons for this:

1) Version of the .NET framework. Make sure the correct version is being loaded or define it in the configuration (app.config)

2) Version hell: some of your assemblies use mismatched versions of other assemblies while you can have one version in your local folder. This is usually the most likely cause.

3) You do not have a reference to an assembly but that is needed by your system and perhaps is loaded dynamically (nhibernate has some dlls like that) and these are not automatically copied to your local test bin folder. Add reference to those DLLs in your local folder.

4) Bitness 32 bit / 64 bit if none managed code is loaded at any point

To find out, check all above. I also suggest you run process monitor by sysinternals. On the file loading events you will see a file not found event. It takes a while to get used to but it is a really good tool.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...