Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'log4net' or one of its dependencies

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.

like image 453
emilios Avatar asked Feb 22 '23 03:02

emilios


2 Answers

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)

like image 154
Steve Avatar answered Mar 29 '23 23:03

Steve


"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).

like image 38
Tuukka Turto Avatar answered Mar 30 '23 01:03

Tuukka Turto