Link to home
Start Free TrialLog in
Avatar of dominicwong
dominicwong

asked on

Mysterious exception "BadImageFormatException" from an un-used DLL in C# project

Hi experts

My C# project imports an external DLL generated by C code. But after I'd removed all references to the DLL in my C# project. I am still getting this exception:
"BadImageFormatException" that complaint about a dll: "Could not load file or assembly file .... TestLib.dll or in one of its dependencies. The module was expected to contain an assembly manifest."

But my program had already removed all references to the DLL.
I'd done a Clean and Rebuilt Solution.
I'd rebooted my PC.
I'd manually deleted all the files in the bin/Debug folder (except the DLL file)

My question is where does the program remember looking for the DLL while I'd already removed it from everywhere I could think of.

Eventually to get rid of the exception, I need to remove the DLL from the folder. But it shouldn't be the case.

Also, my PC is 32-bit Windows XP. So why I am getting this exception that normally happens when 32-bit meets 64-bit??

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of Craig Wagner
Craig Wagner
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dominicwong
dominicwong

ASKER

Thanks CraigWagner. I really thank you for your help!!
That was exactly where my problem was. In some part of my code, I was using reflection to load the assemblies:
            string[] assemblies = Directory.GetFiles(path, "*.dll");
            foreach (string assemblyFile in assemblies)
            {
                    Assembly asm = Assembly.LoadFrom(assemblyFile);
                    foreach (Type t in asm.GetExportedTypes())
                    {
                          :

Open in new window


Now I did as per your illustration and everything works fine. :)
Thanks again. Very much appreciated!!