0

I've gone through another questions here and here but seems that I still could not solve this problem. Even when I try to remove the reference 'log4net' from my program, when I run it still gives the same error. Any ideas?

OS used : Win 7-64 bit.

IDE : Visual Studio 2015

IIS Application Pool setting: enter image description here

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.

=== Pre-bind state information ===
LOG: DisplayName = log4net
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: log4net | Domain ID: 10
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///D:/Codes/Apps/Apps/
LOG: Initial PrivatePath = D:\Codes\Apps\Apps\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Codes\Apps\Apps\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/Apps/6694390a/8e1278d/log4net.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/Apps/6694390a/8e1278d/log4net/log4net.DLL.
LOG: Attempting download of new URL file:///D:/Codes/Apps/Apps/bin/log4net.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

Error Screenshot enter image description here

I would like a solution where it will allow me to use log4net, instead of just removing it completely.

[UPDATE 1]: I tried to use the log4net from

C:\Windows\assembly\GAC_32\log4net\1.2.10.0__692fbea5521e1304\log4net.dll

instead of

C:\Windows\assembly\GAC_64\log4net\1.2.10.0__692fbea5521e1304\log4net.dll

And it seems to work. But I don't understand why. My other projects are using from C:\Windows\assembly\GAC_64\log4net\1.2.10.0__692fbea5521e1304\log4net.dll and it still work. Anyone knows the difference in the project setting that will make using the GAC_64 works?

rcs
  • 6,713
  • 12
  • 53
  • 75

2 Answers2

1

I solved this by creating another application pool, and set Enable 32-bit application to "False".

rcs
  • 6,713
  • 12
  • 53
  • 75
0

Ist log4net still located in your bin folder? It could be as easy as deleting the dll from there (after removing it from your code).

Sometimes you also habe to clean the temporary asp.net folder (c:\windows\Microsoft.NET\Frameword\v4.0.30319\Temporary ASP.NET Files).

If this does not help another package is probably dependent on log4net. Then you have to identify this package and also remove it if you want to get rid of log4net.

  • Actually I want to use the log4net, it's better if the solution is about how we resolve the error. The removal is just for my experiment. – rcs May 14 '18 at 06:15
  • I see... how did you add log4net to yout project? Did you use Nuget? Is log4net.dll copied to your /bin folder? – Stefan Joachimsthaler May 15 '18 at 06:53
  • I copy to the `App_References` folder in my project. This will copy the dll to the bin folder. Removing this from the `App_References` will no longer copy the log4net to bin folder and I can run my project. But I still want to use this log4net.dll. – rcs May 15 '18 at 07:29
  • I think you should not reference the assembly directly and not try to copy a reference and then using it. This can cause version mismatches that are unpredictable. I would try to use Nuget to load log4net. This ensures the matching version of log4net for the .net framework you are using and also adds the correct entries (of necessary) to the web.config file. – Stefan Joachimsthaler May 16 '18 at 08:35