My program compiles nicely, but when I run the program I get this error:
"System.BadImageFormatException thrown calling IO_Init(). Message=An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"
As far as I understand, this error is because my program tries to use a dll which is not the same bitness as my program (which is compiled in 64-bit). I have a 32-bit version of the dll as well, and when I run the 32-bit version of the program, it doesn't throw any error, which is fine.
At the start of my program, I run this to check if we're in 64-bit and if so, go to a folder containing the 64-bit file:
if ((IntPtr.Size > 4) && ((ad.RelativeSearchPath == null) || !ad.RelativeSearchPath.Contains(ad.BaseDirectory + "64\\")))
{
AppDomainSetup aset = new AppDomainSetup();
aset.PrivateBinPath = ad.BaseDirectory + "64\\;" + ad.BaseDirectory;
aset.PrivateBinPathProbe = ad.BaseDirectory + "64\\;" + ad.BaseDirectory;
ad = AppDomain.CreateDomain("_NM64SWITCH_", Assembly.GetAssembly(typeof(NaviModel.Program)).Evidence, aset);
ad.ExecuteAssemblyByName(Assembly.GetAssembly(typeof(NaviModel.Program)).FullName, par);
return;
}
I'm a little lost as to where to look now.
IntPtr.Size > 4
doesn't seems like a good way of checking iа we are running x64 environment. Instead consider usingSystem.Environment.Is64BitOperatingSystem
property. And do you really need to execute your assembly? MaybeAssembly.Load
(and then creating objects from that assembly you're need) is what you're searchnig for?