好吧,我正在构建一个客户端服务器应用程序,它使用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.
这对我并没有告诉我用什么...
关于它的任何最终解决方案? – Kiquenet