2

I wrote a wrapper class for log4net. This wrapper class works correctly with asp.net web application. And now I am trying to test my wrapper class methods using NUNIT. In wrapper class project, I set "Copy Local" to True for log4net DLL. Both NUNIT project and wrapper class are using log4net 1.2.10.0.

This wrapper class works correctly with my separate asp.net web project but some how does not work with my nunit test project.

When I try to run a basic test, I get the following exception

System.BadImageFormatException : Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. An attempt was made to load a program with an incorrect format.

I am running these test within Resharper for VS2010

UPDATE

Just updated my wrapper and test projects with log4net.dll version 1.2.11.0 and every thing starts to work magically!!! I don't know how this latest version fix this problem where 1.2.10.0 kept failing

dotnet-practitioner
  • 13,968
  • 36
  • 127
  • 200

1 Answers1

3

It seems that you are loading a 32-bit DLL on a 64-bit system. You shall build your tests DLL targetting a 32-bit architecture.

Process is described in existing question: Using a 32 bit dll on a 64 bit machine

Community
  • 1
  • 1
German Latorre
  • 10,058
  • 14
  • 48
  • 59
  • why does this wrapper class with log4net(32bit DLL) work with my asp.net web application? – dotnet-practitioner May 02 '12 at 16:04
  • maybe 32-bit compatibility is enabled in IIS app pool (that makes 32-bit DLLs work) or maybe log4net is ok with its bits and there's another DLL or app which is damaging the 64-bit chain. Did you get the same results with NUnit, for instance, to test a different environment? – German Latorre May 02 '12 at 16:45