Could not load file or assembly or one of its dependencies

“Could not load file or assembly or one of its dependencies”. You come across this error message a lot if you are .net developer.

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

could not load file or assembly

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

There are two solution’s for this problem

1 – Make sure you are referencing the correct dll and its there.

2 – if the above solution doesn’t work, You need to enable 32 bit application in your IIS application pool. Attached is the screen shot of where you’ll get that configuration.

Application Pool Advance Settings

Application Pool Advance Settings

Enable 32-bit Applications

Enable 32-bit Applications

Understanding declarative class and instantiating class in .net

While creating an object of any class, the class which is on the left of declaration is called Declarative class and one on the right is called Instantiating class.

Taking an hypothetical example, consider the following class diagram,

Inheritance

Man inheriting from Emotions

 public class Emotions
    {
        public void Laugh()
        {
            Console.WriteLine("Laughing");
        }

        public void Cry()
        {
            Console.WriteLine("Crying");
        }
    }

    public class Man : Emotions
    {
        public void Read()
        {
            Console.WriteLine("Man Reads");
        }

        public void Play()
        {
            Console.WriteLine("Man Plays Cricket");
        }
    }

For the above class when we create object like this,

Emotions e = new Man();

The above object “e” shows following intellisense ,

Void Main

Void Main

e.{will list public functions from Declarative (Emotions) class but will execute from Instantiating (Man) class}

So, in such scenarios (inheritance), when we declare object of base class and instantiate from derived class, objects show public functions, properties and variables of base (declarative) class in intellisense. However if any of those function is overridden, then derived (instantiating) class function is executed.

The above rule does not stand in shadowing. As in shadowing child class shadows the function from base class. So base class is unaware of any such function declaration.  In that scenario base (declarative) class function will be executed.