4

I am trying to create a crystal report and I am new to that field. I have created a crystal report from this tutorial post but it does not seems to work.

My error is :

Could not load file or assembly 'log4net' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'log4net' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'log4net' could not be loaded.

doppelgreener
  • 4,809
  • 10
  • 46
  • 63
emilios
  • 375
  • 1
  • 9
  • 20
  • Have you got log4net installed on your machine? – ChrisF Mar 15 '12 at 21:56
  • Your problem is with log4net, not Crystal Reports. Have you added a reference to the log4net dll? – DJ Quimby Mar 15 '12 at 21:57
  • no i haven't and i don't know how to do that could you please help me. thanks – emilios Mar 15 '12 at 21:58
  • Is your application build against 32bit, 64bit or AnyCPU? Is your IIS version 7? Is IIS running on a 64bit machine? Is log4net.dll the appropriate version for your bit architecture? – Steve Mar 15 '12 at 22:08
  • 1
    AnyCPU, IIS version 7 on a 64bit machine. how do i check the log4net.dll? – emilios Mar 15 '12 at 22:16
  • So you need a full 64bit environment. log4net could be downloaded from [this site](http://logging.apache.org/log4net/download_log4net.cgi). The download is for AnyCPU so should work in your environment, just remember to replace the reference and the binary on your output dir – Steve Mar 15 '12 at 22:43

2 Answers2

7

BadFormatImageException is the error that you receive when your program is compiled for a 32bit architecture and will try to load a 64bit library or viceversa. From the error, you have a reference to log4net (a well known log library).
First, check for what kind of CPU you are creating your application (x86, x64, AnyCPU)
Second, check the bitness of log4net (You should reference the same bitness of your apps)
Third, check on what OS IIS is running. (if is x64 and your app 32, set 'Enable 32-bit Applications' to true in the advanced settings section of the application pool)

Steve
  • 213,761
  • 22
  • 232
  • 286
1

"An attempt was made to load a program with an incorrect format." could be because some of your dlls are 32 bit and some are 64 bit. Another reason could be that your application server is configured for 64bit and dlls are 32bit (or other way around).

I would first check settings of the IIS (this depends on the version of IIS you are using) and then check are dlls compiled to 32bit or 64bit (from myproject settings).

Tuukka Turto
  • 145
  • 1
  • 2
  • 7