BadImageFormatException 故障排除 [英] Troubleshooting BadImageFormatException

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

问题描述

我有一个使用 Visual Studio 2010 用 C# 编写的 Windows 服务,目标是完整的 .NET Framework 4.当我从调试版本运行时,服务按预期运行.但是,当我从 Release 版本运行它时,我得到一个 System.BadImageFormatException(详细信息如下).我一直在互联网上寻找解决方案,但到目前为止我发现的每件事都没有帮助我找到解决方案.

该问题存在于 Windows 7 64 位(开发)和 Windows XP SP3 32 位(目标)系统上.

这是我迄今为止尝试过的:

  • 经过验证的构建设置(例如 Platform Target)都相同 (x86).
  • 将 peverify 与/verbose 选项一起使用以确保程序集二进制文件有效.
  • 使用 fuslogvw 查找任何加载问题.
  • 使用 CheckAsm 查找丢失的文件或程序集.

所有这些检查都没有改变任何东西.我在下面包含了例外信息的全文,其中一些名称已更改以保护我公司主人的秘密.

<前>System.BadImageFormatException 未处理Message=无法加载文件或程序集XxxDevices,版本=1.0.0.0,Culture=neutral,PublicKeyToken=null"或其依赖项之一.试图加载格式不正确的程序.源 = XxxDevicesService文件名=XxxDevices,版本=1.0.0.0,文化=中性,PublicKeyToken=nullFusionLog=从以下位置加载的程序集管理器:C:WindowsMicrosoft.NETFramework64v4.0.30319clr.dll在可执行文件 c:DevTeamEinReleaseXxxDevicesService.vshost.exe 下运行--- 详细的错误日志如下.=== 预绑定状态信息 ===日志:用户 = XXX日志:DisplayName = XxxDevices,版本=1.0.0.0,文化=中性,PublicKeyToken=null(完全指定)日志:Appbase = file:///c:/Dev/TeamE/bin/Release/日志:初始 PrivatePath = NULL调用程序集:XxxDevicesService,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null.===LOG:此绑定在默认加载上下文中启动.LOG:使用应用程序配置文件:c:TeamEinReleaseXxxDevicesService.vshost.exe.ConfigLOG:使用主机配置文件:日志:使用来自 C:WindowsMicrosoft.NETFramework64v4.0.30319configmachine.config 的机器配置文件.日志:此时未将策略应用于引用(私有、自定义、部分或基于位置的程序集绑定).日志:正在尝试下载新的 URL 文件:///c:/TeamE/bin/Release/XxxDevices.DLL.ERR: 未能完成装配设置 (hr = 0x8007000b).探测终止.堆栈跟踪:在 XxxDevicesService.Program.Main(String[] args)在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)在 System.Threading.ThreadHelper.ThreadStart()内部异常:

解决方案

经过验证的构建设置(例如平台目标)都相同 (x86).

那不是崩溃日志所说的:

<块引用>

程序集管理器加载自:C:WindowsMicrosoft.NETFramework64

注意名称中的 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:WindowsMicrosoft.NETFramework64v4.0.30319clr.dll
Running under executable  c:DevTeamEinReleaseXxxDevicesService.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:TeamEinReleaseXxxDevicesService.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFramework64v4.0.30319configmachine.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:WindowsMicrosoft.NETFramework64

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天全站免登陆