OK、WinFormsアプリケーションによってホストおよび消費されるNetTcpBindingを使用してWCFを使用してクライアントサーバーアプリケーションを構築しています。Windows 7Ultimatex64でVS.2012Ultimateを使用しています。
サービスをホストするWinFormを開始し、サービスを開始できます。ここで、クライアント側でクライアントアプリケーションを起動すると、すぐにMicrosoftWCFサービスホストウィンドウが表示されます。
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)と同じターゲットプラットフォーム(任意のCPUではなくx86)に設定されていることを確認しました。
さらに、唯一の外部アセンブリ参照(ユーティリティライブラリDLL)も、同じフレームワーク(4.5)および同じプラットフォーム(x86)に対して、同じVSバージョンで構築されています。
では、この悪い画像フォーマットはどこから来ているのでしょうか?ソリューションには外部ライブラリの独自のコピーがあり(プラットフォームとフレームワークの構成が正しいことを確認するため)、プロジェクトファイルは、対応するリリース/デバッグバージョンの外部アセンブリを使用するように変更されています。
例外からのヒントに従って、regeditを使用して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.
これは私には何の役にも立ちません...