我有一个使用Visual Studio 2010用C#编写的Windows服务,目标是完整的.NET Framework 4.当我从Debug构建运行时,服务按预期运行.但是,当我从Release版本运行它时,我得到一个System.BadImageFormatException(详情如下).我一直在网上寻找解决方案,但到目前为止,我发现的每件事都没有帮助我找到解决方案.
Windows 7 64位(dev)和Windows XP SP3 32位(目标)系统都存在此问题.
这是我到目前为止所尝试的:
所有这些检查都没有改变任何东西.我已经在下面列出了例外信息的全文,其中一些名称已经更改,以保护我公司主人的秘密.
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:
Han*_*ant 116
已验证的构建设置(例如Platform Target)都是相同的(x86).
这不是崩溃日志所说的:
装配管理器从:C:\ Windows\Microsoft.NET\Framework64加载
注意名称中的64,这是64位版本框架的主页.在EXE项目上设置目标平台设置,而不是类库项目.XxxDevicesService EXE项目确定进程的位数.
小智 37
在我不停地敲桌子后想着整个星期,我花了这个问题,我正在分享对我有用的东西.我有Win7 64位,32位Oracle客户端,并且我的MVC 5项目设置为在x86平台上运行,因为Oracle的位数.我一直得到同样的错误:
无法加载文件或程序集"Oracle.DataAccess"或其依赖项之一.尝试加载格式不正确的程序.
我重新加载了NuGet包,我使用了在不同应用程序中为其他人工作的DLL的副本,我将依赖程序集中的代码库设置为指向我项目的bin文件夹,我尝试将CopyLocal设置为true或false,我尝试了一切. 最后我做了足够的其他事情,我想检查我的代码,作为一个新的承包商,我没有设置颠覆.在寻找将其挂钩到VS的方法时,我绊倒了答案.我发现的工作是取消选中Tools => Options菜单下的Projects and Solutions => Web Projects部分下的"使用64位版本的IIS Express for Web Sites and Projects"选项.
小智 20
我发现的工作是在Tools => Options菜单下的Projects and Solutions => Web Projects部分下检查"使用64位版本的IIS Express for Web Sites and Projects"选项.
小智 14
仅将平台目标设置为x86并不能解决我的问题。我必须在项目属性中将Bitness 更改为x86
如下:
属性 -> 网页 -> 位数
小智 12
当您更改.csproj的目标框架并将其恢复为您的开始时,通常会发生这种情况.
在app.config中的启动标记下,确保1如果supportedRuntime version ="与cs项目目标不同的运行时".
确保2这也意味着检查属性文件夹中的其他自动生成或其他文件,以查看这些文件与.csproj文件中定义的文件之间是否没有更多的运行时不匹配.
在开始尝试使用项目属性来解决错误之前,这些可能只会节省大量时间.
当您的应用程序以.NET Framework 4.5为目标(例如)并且您具有以下app.config时,也可以获得此异常:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v4.0" />
</startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)
尝试启动应用程序的调试时,您将获得BadImageFormatException.
删除声明v2.0版本的行将清除错误.
最近,当我尝试将目标平台从旧的.NET 2.0项目更改为.NET 4.5时,我遇到了这个问题.
背景
今天我们在运行IIS 6.2的Windows 2012 R2服务器上将我们的WCF服务从AnyCPU切换到x64时就开始了.
首先,我们检查了唯一引用的程序集10次,以确保它实际上不是x86 dll.接下来,我们多次检查应用程序池,以确保它不启用32位应用程序.
我一时兴起试图切换设置.事实证明,IIS中的应用程序池默认为启用32位应用程序值为False,但IIS出于某种原因忽略了它在我们的服务器上,并始终在x86模式下运行我们的服务.
解
归档时间: |
|
查看次数: |
167963 次 |
最近记录: |