我有一个适用于大多数Windows 10(64位)系统的应用程序,但有6台计算机正在获得相同的BadImageFormatException。应用程序和库的目标是AnyCPU。尝试从程序集创建COM对象时,我得到异常:
无法加载文件或程序集“InfoConnectCOM.Wrapper64.dll”或其中一个 它的依赖关系。不是有效的Win32应用程序。 (例外 HRESULT:0x800700C1)
基于包装器的名称,它看起来应该引用x64程序集。最近有30台计算机以相同的方式成像,只有6台有这个问题。此外,还有几百台其他Win10(64位)计算机没有遇到此问题。
Private _system As Object
Private Const IC16AssemblyName As String = "InfoConnectCOM.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=13bff1b6907eadcf"
Private Sub CreateIC16SystemObject()
Dim assembly As Reflection.Assembly = Reflection.Assembly.Load(IC16AssemblyName)
Dim type As System.Type = assembly.GetType("Accmgr.AccmgrSystemWrapper")
_system = Activator.CreateInstance(type)
End Sub
程序集是动态加载的,因为我需要代码在不同平台上使用不同版本的软件。
Stacktrace System.Reflection.TargetInvocationException
System.RuntimeTypeHandle.CreateInstance(type As RuntimeType, publicOnly As Boolean, noCheck As Boolean, canBeCached As Boolean&, ctor As RuntimeMethodHandleInternal&, bNeedSecurityCheck As Boolean&)
QCC.exe: N 00000
System.RuntimeType.CreateInstanceSlow(publicOnly As Boolean, skipCheckThis As Boolean, fillCache As Boolean, stackMark As StackCrawlMark&)
QCC.exe: N 00142
System.Activator.CreateInstance(type As Type, nonPublic As Boolean)
QCC.exe: N 00105
System.Activator.CreateInstance(type As Type)
QCC.exe: N 00012
IAT.AccMgr.Session.CreateIC16SystemObject()
QCC.exe: N 00060
IAT.AccMgr.Session.CreateSystemObject()
QCC.exe: N 00029
IAT.AccMgr.Session..ctor()
QCC.exe: N 00163
Stacktrace BadImageFormatException
System.Reflection.RuntimeAssembly._nLoad(fileName As AssemblyName, codeBase As String, assemblySecurity As Evidence, locationHint As RuntimeAssembly, stackMark As StackCrawlMark&, pPrivHostBinder As IntPtr, throwOnFileNotFound As Boolean, forIntrospection As Boolean, suppressSecurityChecks As Boolean)
QCC.exe: N 00000
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(assemblyRef As AssemblyName, assemblySecurity As Evidence, reqAssembly As RuntimeAssembly, stackMark As StackCrawlMark&, pPrivHostBinder As IntPtr, throwOnFileNotFound As Boolean, forIntrospection As Boolean, suppressSecurityChecks As Boolean)
QCC.exe: N 00457
System.Reflection.RuntimeAssembly.InternalLoadFrom(assemblyFile As String, securityEvidence As Evidence, hashValue As Byte[], hashAlgorithm As AssemblyHashAlgorithm, forIntrospection As Boolean, suppressSecurityChecks As Boolean, stackMark As StackCrawlMark&)
QCC.exe: N 00182
System.Reflection.Assembly.LoadFrom(assemblyFile As String, securityEvidence As Evidence)
QCC.exe: N 00056
System.Activator.CreateInstanceFromInternal(assemblyFile As String, typeName As String, ignoreCase As Boolean, bindingAttr As BindingFlags, binder As Binder, args As Object[], culture As CultureInfo, activationAttributes As Object[], securityInfo As Evidence)
QCC.exe: N 00029
Accmgr.AccmgrSystemWrapper.CreateAccmgrSystemWrapper(installDir As String)
QCC.exe: N 00086
Accmgr.AccmgrSystemWrapper..ctor()
QCC.exe: N 00045
我们已尝试卸载并重新安装InfoConnect软件。如果我将我的代码和库更改为目标x86,那么它就会运行。但是,我想避免重新编译所有软件以定位x86。
有关如何继续排除此故障或为何只会影响少量计算机的任何想法?
由于
答案 0 :(得分:0)
原来计算机上唯一的C Redistributable Library是32位版本。 COM包装器在C中,因此当它试图加载mvscr120.dll时,错误的版本被拉出。修复解决了这个问题。