【问题标题】:.NET 4.0 WinForm - Could not load file or assembly or one of its dependencies. is not a valid Win32 application.NET 4.0 WinForm - 无法加载文件或程序集或其依赖项之一。不是有效的Win32应用程序
【发布时间】:2018-11-04 06:14:53
【问题描述】:

我有一个可以在大多数 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

堆栈跟踪 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。

关于如何继续解决此问题或为什么只有少数计算机会受到影响的任何想法?

谢谢

【问题讨论】:

    标签: vb.net winforms com .net-4.0 badimageformatexception


    【解决方案1】:

    原来机器上唯一的 C Redistributable Library 是 32 位版本。 COM Wrapper 是 C 语言,所以当它试图加载 mvscr120.dll 时,会拉出错误的版本。修复已解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-12
      • 2012-01-14
      • 1970-01-01
      相关资源
      最近更新 更多