我的程序编译得很好,但是当我运行该程序时,出现此错误:
"System.BadImageFormatException thrown calling IO_Init(). Message=An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"
据我了解,此错误是因为我的程序尝试使用与我的程序(以 64 位编译)位数不同的 dll。我也有 32 位版本的 dll,当我运行该程序的 32 位版本时,它不会抛出任何错误,这很好。
在程序开始时,我运行它来检查我们是否处于 64 位,如果是,则转到包含 64 位文件的文件夹:
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;
}
我现在有点迷失方向。
最佳答案
从任何 CPU 切换到 x86 为我解决了这个问题。
关于c# - 尝试加载格式不正确的程序 (.dll),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26117618/