I’m trying to load a mixed managed/native dll, which I compiled for 32 bit and for 64 bit.
If I run my program on Windows 7 32 bit, I can load the 32 bit dll without any problem. If I load the 64 bit dll, I get BadImageFormatException, which is what I expected.
The problem I have is when I do the same test under Windows 7 64 bit:
If I load the 32 bit dll, I get BadImageFormatException. This is ok so far.
But if I load the 64 bit dll, I get FileNotFoundException. And this information is just not true, because I check the existance of this dll beforehand!
Can anybody tell me, why I can’t load my 64 bit dll under windows 7 64 bit?
Here is my sample code:
private void Button32_Click(object sender, RoutedEventArgs e)
{
string path = System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "x86", "Native.dll");
LoadAssembly(path);
}
private void Button64_Click(object sender, RoutedEventArgs e)
{
string path = System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "amd64", "Native.dll");
LoadAssembly(path);
}
void LoadAssembly(string path)
{
if(File.Exists(path))
{
MessageBox.Show("Loading " + path);
Assembly asm = null;
try
{
asm = Assembly.LoadFile(path);
}
catch(Exception ex)
{
MessageBox.Show("Exception!!!\n" + ex);
}
MessageBox.Show("Success " + (asm == null ? "no" : "yes"));
}
}
You should try to know which assembly cannot be loaded because maybe the assembly you try to load have references that can’t be found. Or reference are present but for 32bit, not the 64bit version
Try to use Fusion log to know exactly which assembly is missing