Click here to Skip to main content
16,012,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I was using log4net in framework 2.0, and it was working fine. Now i am building a app in framwork 4.0 and it is giving an error.
This is the code i am using.
C#
public class DBHelper : IDisposable
    {

       private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(DBHelper));
        private const string EDK = "11d50a3a";
        private static Hashtable connStrings = new Hashtable();
        private const bool m_bUseDummyReader = true;
        DbTransaction transaction;
        IDbConnection connection;        

        private string databaseName;
        private Database CurrDB;

        cfsEncryption cfsEncrypt = new cfsEncryption();

        public DBHelper(string strDB)
        {            
            Init(strDB, IsolationLevel.ReadCommitted);
        }
        private void Init(string strDB, IsolationLevel iso)
        {

            databaseName = strDB;
            try
            {
                CurrDB = DatabaseFactory.CreateDatabase(strDB);
                connection = CurrDB.CreateConnection();
                connection.Open();
                transaction = (DbTransaction)connection.BeginTransaction();

            }
            catch (Exception ex)
            {
                if ((log.IsErrorEnabled))
                    log.Error(string.Format(System.Globalization.CultureInfo.CurrentCulture,
                        "Connection to DB ->{0} Failed", strDB), ex);

                throw;
            }
        }

This is the error i am getting.
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
Posted
Updated 27-Dec-11 7:07am
v2

1 solution

The log4net DLL was probably built for x86 and you are running on 64bit or vise-versa.

Try compiling the log4net from source and changing the target platform to match your main project.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-Dec-11 14:50pm    
Reasonable idea, a 5.
--SA
Mehdi Gholam 27-Dec-11 14:58pm    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900