好吧,我正在構建一個客戶端服務器應用程序,它使用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