While attaching to some process in Visual Studio 2012, I'm getting such an error:
Complete exception is shown below:
System.BadImageFormatException: Could not load file or assembly 'C:\Program Files (x86)\SDK\Serv\bin\Debug\Service.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'file:///C:\Program Files (x86)\SDK\Serv\bin\Debug\Service.dll'
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)
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
What is the reason of such an issue and how to avoid it ?
Update to provide more details
When logging is enabled in Assembly Binding Log Viewer (FUSLOGVW.exe in Windows SDK), the log shows:
The operation failed.
Bind result: hr = 0x8007000b. An attempt was made to load a program with an incorrect format.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\WcfSvcHost.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = EUROPE\JAWAL
LOG: Where-ref bind. Location = C:\Program Files (x86)\SDK\Serv\bin\Debug\Service.dll
LOG: Appbase = file:///C:/Program Files (x86)/SDK/Serv/bin/Debug
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = 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: C:\Program Files (x86)\SDK\Serv\bin\Debug\Service.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:///C:/Program Files (x86)/SDK/Serv/bin/Debug/Service.dll.
LOG: Assembly download was successful. Attempting setup of file: C:\Program Files (x86)\SDK\Serv\bin\Debug\Service.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Service, Version=6.100.4434.0, Culture=neutral, PublicKeyToken=null
ERR: Invalid assembly platform or ContentType in file (hr = 0x8007000b).
ERR: Run-from-source setup phase failed with hr = 0x8007000b.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
The service definition is as follows:
[ServiceContract(SessionMode = SessionMode.Required)]
[ServiceKnownType(typeof(TypeInfo))]
public interface IServiceContract
{
[OperationContract]
[FaultContract(typeof(ServiceFault), Name = "ServiceFault")]
string GetConfiguration();
[OperationContract]
[FaultContract(typeof(ServiceFault), Name = "ServiceFault")]
void SaveConfiguration(string config);
[OperationContract]
[FaultContract(typeof(ServiceFault), Name = "ServiceFault")]
byte[] GetImage(int x, int y);
[OperationContract]
[FaultContract(typeof(ServiceFault), Name = "ServiceFault")]
IList<ITypeInfo> GetSupportedTypes();
}
[DataContract(Namespace = Namespaces.Data)]
public class ServiceFault
{
private string _message;
[DataMember]
public string Message { get { return _message; } set { _message = value; } }
public ServiceFault() { }
public ServiceFault(string message) { _message = message; }
}
public interface ITypeInfo
{
string Type { get; }
string Description { get; }
}
public class TypeInfo : ITypeInfo
{
public string Type { get; set; }
public string Description { get; set; }
}
You need to find in your soultion (VS solution) the projects which has "WCF Options" section as on the picture above and deselect "Start WCF Service Host when debugging another project in the same solution". Although I don't know the consequences except the one that you will not have this dialog anymore. found on: How to Prevent Visual Studio launch WcfSvcHost.exe in Debuggin? and tested by myself.