Mulitplatform应用程序在Relase模式下与System.BadImageFormatException崩溃,但在Debug

时间:2016-07-06 19:59:51

标签: c# 64-bit badimageformatexception

我有一个应用程序,我最近不得不添加一个混合平台(一些32位某些64位)组件。对于64位版本,一个.exe是32位,其余是64位,并且所有DLL都设置为“任何CPU”(因为它们需要在两个平台之间共享)。我在Debug中编译时一切正常。 64位应用程序工作,32位应用程序工作,他们共享所有DLL没有问题。当我更改为Release模式时,我在尝试启动64位应用程序时遇到System.BadImageFormatException(请注意,32位组件运行正常)。错误如下:

System.BadImageFormatException was unhandled
  FileName=XXXXXXXXX.Framework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
  FusionLog==== Pre-bind state information ===
LOG: DisplayName = XXXXXXXXX.Framework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///D:/company/branches/product/2.6/product/product/bin/Release/x64/
LOG: Initial PrivatePath = NULL
Calling assembly : product, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\company\branches\product\2.6\product\product\bin\Release\x64\product.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///D:/company/branches/product/2.6/product/product/bin/Release/x64/XXXXXXXXX.Framework.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

  HResult=-2147024885
  Message=Could not load file or assembly 'XXXXXXXXX.Framework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
  Source=product
  StackTrace:
       at product.App.OnStartup(StartupEventArgs e)
       at System.Windows.Application.<.ctor>b__1_0(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at product.App.Main() in D:\company\branches\product\2.6\product\product\obj\x64\Release\App.g.cs:line 51
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

现在,当我比较配置管理器中的配置时,它们是相同的,除了一个是Release而另一个是Debug。

调试构建配置:

enter image description here

发布构建配置:

enter image description here

列表中更远的所有其他项目都是dll,并且在两种配置中都设置为“Any CPU”。 为什么在发布时这不起作用?这没有任何意义。我几乎试图发布Debug版本,因为它的工作方式与我想要的完全一致。我已经检查了以下堆栈问题以获得我的答案,但它们只是略有不同。另外,我没有选择只能只构建32位。我需要两个平台,但64位由于某种原因失败。

0 个答案:

没有答案