1

好吧,我正在构建一个客户端服务器应用程序,它使用WCF和由WinForms应用程序托管和使用的NetTcpBinding。我在Windows 7 Ultimate x64中使用VS.2012 Ultimate。WcfSvcHost当执行WCF服务应用程序时出现BadImageFormatException

我可以启动承载服务的winform,并启动服务。现在,在客户端,我开始在客户端应用程序,并立即得到了微软WCF服务主机窗口,告诉我:

System.BadImageFormatException. Could not load file or assembly X.Services.dll ... an 
attempt was made to load a program with an incorrect format. 
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) 
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) 
at System.Reflection.Assembly.Load(AssemblyName assemblyRef) 
at Microsoft.Tools.SvcHost.ServiceHostHelper.LoadServiceAssembly(String svcAssemblyPath) 

现在,客户端和服务器的WinForm项目的X.Services.dll参考其定义服务(接口&实现类)。那么,为什么服务器不会抱怨呢?

此外,我已确保此解决方案中的所有项目都将其调试&发行版配置设置为相同的.NET Framework(4.5)和SAME目标平台(x86而不是任何CPU)。

此外,对于相同的框架(4.5)和相同的平台(x86),唯一的外部程序集引用(实用程序库DLL)也是使用相同的VS版本构建的。

那么这个不好的图像格式来自哪里呢?该解决方案拥有自己的外部库副本(以确保它具有合适的平台&框架配置),并且项目文件已被修改,以便它采用外部程序集的相应版本/调试版本。

继从我使用注册表编辑器在HKLM添加一键实现的组件负载/绑定日志记录,并得到这些额外的信息除外提示:

=== Pre-bind state information === 
LOG: User = DOMAIN\Username 
LOG: Where-ref bind. Location = D:\Sources\My.Net\Code\T\X.Services\bin\Debug\X.Services.dll 
LOG: Appbase = file:///D:\Sources\My.Net\Code\T\X.Services\bin\Debug\X.Services/bin/Debug 
LOG: Initial PrivatePath = NULL 
Calling assembly : (Unknown). 
=== 
LOG: This bind starts in LoadFrom load context. 
WRN: Native image will not be probed in LoadFrom context. Native image will only be  probed in default load context, like with Assembly.Load(). 
LOG: Using application configuration file: D:\Sources\My.Net\Code\T\X.Services\bin\Debug\X.Services.dll.config 
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. 
LOG: Attempting download of new URL file:///D:\Sources\My.Net\Code\T\X.Services\bin\Debug\X.Services.dll. 
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated. 

这对我并没有告诉我用什么...

+0

关于它的任何最终解决方案? – Kiquenet

回答

0

可能是在问题:

日志:从C使用计算机配置文件:\ WINDOWS \ Microsoft.NET \框架 \ v 4.0 .30319 \ config \ machine.config。

看来应用程序在.NET 4.0 x64下启动。 尝试分析您的程序集(例如,通过.NET Framework SDK中的corflags.exe)以确定所需的平台和.NET版本。

+0

什么是64位框架的问题? –

0

我不知道这是否仍然有效,但它与this thread中的问题相同。 解决方案是运行x86中的每个进程,如here

这是最简单的创建第二个WcfSvcHost为x86类别是这样的:

开始管理员权限的CMD环境:

C:\

CD“C: \ Program Files文件(x86)\ Microsoft Visual Studio 10。0 \ Common7 \ IDE”

C:\ Program Files文件(x86)的\微软的Visual Studio 10.0 \ Common7 \ IDE

复制WcfSvcHost.exe WcfSvcHost32.exe 1文件(S)复制。

C:\ Program Files文件(x86)的\微软的Visual Studio 10.0 \ Common7 \ IDE

corflags位/ 32位+ /力WcfSvcHost32.exe弥crosoft(R).NET Framework CorFlags转换工具。版本4.0.30319.1版权所有(c) 微软公司。版权所有。

corflags:warning CF011:指定的文件是强名称签名。
使用/强制将使该图像的签名无效,并且 将要求放弃该程序集。

C:\ Program Files文件(x86)的\微软的Visual Studio 10.0 \ Common7 \ IDE

然后你可以举办各种命令你的项目:

WcfSvcHost32.exe /服务:% enteryourservicenamehere%.dll /config:%yourconfigfilehere.dll.config%

这就是为我工作的。

相关问题