开发者

System.BadImageFormatException - can't solve it

I'm using Visual Studio 2010, running in Windows 7 X64 I was trying to create a simple WCF implementation of duplex communication. Sadly enough I got stuck very quickly.

I have 3 projects: - Service library with simple service contract and the implementation - ServiceHost: Hosting the service library via SelfHosting - Client: Consuming a method from the WCF service

Something I immediately noticed that the Service library had Any CPU as platform . The other two had x86 as platform . At this point I had no idea I would get this error, so this didn't really bother me.

Then I started the service library using the built in wcfsvchost.exe. Service was hosted without a problem. Then I wanted to host my service via my own host. Here I got my first experience with System.BadImageFormatException. I had no idea what it was at that point. So I was stuck and did some googling. If I understand correctly the platform of all the dlls etc. need to be the same. if someone can explain me a little better. Please do.

Anyway so I though I would change the platform of the service library because this had Any CPU instead of x86. So I tried to do it via the Project settings and the configuration manager. But the problem is I had not the option to change it. Then I unloaded the project, looked what the other .csproj looked like it and changed the values there. Reloaded it and everything was fine. Now it had the correct platform, x86 . Ok so let's test run the service library..BOOM System.BadImageFormatException

System.BadImageFormatException: Could not load file or assembly 'file:///C:\Users\Sven\documents\visual studio 2010\Projects\DuplexDemo\CustomerService2\bin\Debug\CustomerService2.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format. File name: 'file:///C:\Users\Sven\documents\visual studio 2010\Projects\DuplexDemo\CustomerService2\bin\Debug\CustomerService2.dll' at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.Assembly.Load(AssemblyName assemblyRef) at Microsoft.Tools.SvcHost.ServiceHostHelper.LoadServiceAssembly(String svcAssemblyPath)

=== Pre-bind state information === LOG: User = Sven-PC\Sven LOG: Where-ref bind. Location = C:\Users\Sven\documents\visual studio 2010\Projects\DuplexDemo\CustomerService2\bin\Debug\CustomerService2.dll LOG: Appbase = file:///C:/Users/Sven/documents/visual studio 2010/Projects/DuplexDemo/CustomerService2/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: C:\Users\开发者_开发百科Sven\documents\visual studio 2010\Projects\DuplexDemo\CustomerService2\bin\Debug\CustomerService2.dll.config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.21006\config\machine.config. LOG: Attempting download of new URL file:///C:/Users/Sven/documents/visual studio 2010/Projects/DuplexDemo/CustomerService2/bin/Debug/CustomerService2.dll. ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

So now that I had changed the platform the service library wouldn't run anymore. So now I'm stuck and I seek some solutions.

Can anyone tell me what's going on? Don't think the code is having errors because it's all plain vanilla WCF and before it was working. The code is also working when created in x32 setup

Please help me out


This is perhaps a VERY long shot in the dark, but could you run the app pool in 32bit mode?

I am guessing you do not want to do this, because it seems you have been looking at this problem for some time?

The way that I fixed a similar problem, was one by one going through the libraries I used till I found the offending 3 party library that was not 64bit compatible.

Best Regards Rihan

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜