故障排除BadImageFormatException [英] Troubleshooting BadImageFormatException

查看:265
本文介绍了故障排除BadImageFormatException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows服务在C#编写使用Visual Studio 2010和针对完整的.NET框架4。当我从一个调试运行构建服务运行正常。然而,当我从一个发布版本运行它,我得到(下面详细说明)一System.BadImageFormatException。我一直在互联网上寻找一个解决方案,但到目前为止,每一件事,我发现并没有帮助我找到一个解决方案。

问题存在于在Windows 7 64位(DEV)和Windows XP SP3 32位(目标)系统。

下面是我到目前为止已经试过:

  • 验证构建设置等平台的目标都是相同的(86)。
  • 与/ verbose选项,以保证装配的二进制文件是有效使用peverify。
  • 使用fuslogvw寻找任何加载问题。
  • 二手CheckAsm寻找丢失的文件或assembiles。

所有这些检查没有任何改变。我已经包含了下面的异常信息的全文,与一些名字改来保护我的企业主人的秘密。

System.BadImageFormatException是未处理
  消息=无法加载文件或程序集XxxDevices,版本= 1.0.0.0,文化=中性公钥= null或它的一个依赖。试图用不正确的格式加载程序。
  来源= XxxDevicesService
  文件名= XxxDevices,版本= 1.0.0.0,文化=中性公钥=空
  C:从FusionLog =大会经理装\的Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ clr.dll
下可执行的C运行:\开发\ TeamE \ BIN \发布\ XxxDevicesService.vshost.exe
---详细的错误日志如下。

=== pre-绑定状态信息===
日志:用户= XXX
日志:显示名称= XxxDevices,版本= 1.0.0.0,文化=中性公钥=空
 (完全限定)
日志:应用平台=文件:/// C:/开发/ TeamE /斌/发行/
LOG:初始PrivatePath = NULL
调用汇编:XxxDevicesService,版本= 1.0.0.0,文化=中性公钥=空。
===
日志:此绑定从default加载上下文。
日志:正在使用应用程序配置文件:C:\ TeamE \ BIN \发布\ XxxDevicesService.vshost.exe.Config
日志:使用主机配置文件:
日志:从C使用计算机配置文件:\ WINDOWS \ Microsoft.NET \ Framework64 \ v4.0.30319 \ CONFIG \ machine.config中。
日志:政策不被应用到引用在这个时候(私人,自定义,局部的,或基于位置的程序集绑定)。
日志:新的URL文件试图下载:/// C:/TeamE/bin/Release/XxxDevices.DLL。
错误:未能完成安装的组件(HR = 0x8007000b)。探测终止。

  堆栈跟踪:
       在XxxDevicesService.Program.Main(字串[] args)
       在System.AppDomain._nExecuteAssembly(RuntimeAssembly组装,字串[] args)
       在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在System.Threading.ExecutionContext.Run(ExecutionContext中的ExecutionContext,ContextCallback回调,对象的状态,布尔ignoreSyncCtx)
       在System.Threading.ExecutionContext.Run(ExecutionContext中的ExecutionContext,ContextCallback回调,对象的状态)
       在System.Threading.ThreadHelper.ThreadStart()
  的InnerException:

解决方案
  

验证构建设置,如平台的目标都是相同的(86)。

这不是崩溃日志说:

  C:从

装配经理装\的Windows \ Microsoft.NET \ Framework64

注意的 64 的名称中,这是在64位版本的框架家。将您的 EXE 的项目,而不是你的类库项目的目标平台设置。该XxxDevicesService EXE项目确定处理的位数。

I have a Windows service written in C# using Visual Studio 2010 and targeting the full .NET Framework 4. When I run from a Debug build the service runs as expected. However, when I run it from a Release build I get a System.BadImageFormatException (details below). I've been searching the internet for a solution but so far every thing I've found hasn't helped me find a solution.

The problem exists on both Windows 7 64-bit (dev) and Windows XP SP3 32-bit (target) systems.

Here is what I've tried so far:

  • Verified build settings such as Platform Target are all the same (x86).
  • Used peverify with the /verbose option to ensure the assembly binaries were valid.
  • Uses fuslogvw to look for any loading issues.
  • Used CheckAsm to look for missing files or assembiles.

All of these checks didn't change anything. I've included the full text of the exception information below, with some of the names changed to protect the secrets of my corporate masters.

System.BadImageFormatException was unhandled
  Message=Could not load file or assembly 'XxxDevices, 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=XxxDevicesService
  FileName=XxxDevices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
  FusionLog=Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  c:\Dev\TeamE\bin\Release\XxxDevicesService.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = XXX
LOG: DisplayName = XxxDevices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///c:/Dev/TeamE/bin/Release/
LOG: Initial PrivatePath = NULL
Calling assembly : XxxDevicesService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\TeamE\bin\Release\XxxDevicesService.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:///c:/TeamE/bin/Release/XxxDevices.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

  StackTrace:
       at XxxDevicesService.Program.Main(String[] args)
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

解决方案

Verified build settings such as Platform Target are all the same (x86).

That's not what the crash log says:

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64

Note the 64 in the name, that's the home of the 64-bit version of the framework. Set the Target platform setting on your EXE project, not your class library project. The XxxDevicesService EXE project determines the bitness of the process.

这篇关于故障排除BadImageFormatException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆