System.BadImageFormatException - 无法解决它 [英] System.BadImageFormatException - can't solve it

查看:73
本文介绍了System.BadImageFormatException - 无法解决它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我正在使用Visual Studio 2010,在Windows 7 X64中运行。我试图创建一个简单的双工通信WCF实现。
可悲的是我得到了很快就被卡住了。

我有3个项目:
- 服务图书馆简单的服务合同和实施 - ServiceHost:通过SelfHosting托管服务库
- 客户:从WCF服务中使用方法

我立即注意到服务库有任何CPU作为平台。其他两个以 x86作为平台
在这一点上我不知道我会得到这个错误,所以这并没有真正打扰我。

那么我使用内置的wcfsvchost.exe启动了服务库。托管服务没有问题。
然后我想通过我自己的主机托管我的服务。在这里,我第一次体验到System.BadImageFormatException。我不知道那时是什么。
所以我被困住并做了一些谷歌搜索。如果我理解正确,所有dll等平台需要相同。 如果有人能更好地解释我请你这样做。

无论如何我会改变服务库的平台,因为它有任何CPU而不是x86。所以我尝试通过Project设置来做和配置管理器。但问题是我无法改变它。然后我卸载了项目,看看另一个.csproj看起来像是什么并改变了那里的值。重装上阵,一切都很好。现在它有了正确的平台, x86 。好的,让我们测试运行服务库.. BOOM System.BadImageFormatException

System.BadImageFormatException:无法加载文件或程序集'file:/// C:\ Users \Sven \\ \\documents\visual studio 2010 \Projects\DuplexDemo \CustomerService2 \bin\Debug \ Customer.com2.dll'或其中一个依赖项。尝试加载格式不正确的程序。
文件名:'file:/// C:\Users\Sven\documents\visual studio 2010 \Projects \DuplexDemo \ CustomerService2\bin\Debug\CustomerService2.dll'  在System.Reflection.RuntimeAssembly._nLoad(的AssemblyName文件名,字符串的代码库,证据assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark&安培; stackMark,布尔throwOnFileNotFound,布尔forIntrospection,布尔suppressSecurityChecks)
  在System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(的AssemblyName assemblyRef,证据assemblySecurity,StackCrawlMark&安培; stackMark,布尔forIntrospection,布尔suppressSecurityChecks)
  在System.Reflection.Assembly.Load(AssemblyName assemblyRef)
  在Microsoft.Tools.SvcHost.ServiceHostHelper.LoadServiceAssembly(String svcAssemblyPath)

= ===预绑定状态信息===
LOG:User = Sven-PC\Sven
日志:Where-ref绑定。位置= C:\Users\Sven\documents\visual工作室2010\Projects\DuplexDemo\CustomerService2\bin\Debug\CustomerService2.dll
日志:应用平台=文件:// / C:/ Users / Sven / documents / visual studio 2010 / Projects / DuplexDemo / CustomerService2 / bin / Debug
LOG:Initial PrivatePath = NULL
调用程序集:(未知)。
== =
日志:此绑定在LoadFrom加载上下文中开始。
警告:在LoadFrom上下文中不会探测本机映像。原生图像只能在默认加载上下文中进行探测,就像使用Assembly.Load()一样。
日志:使用应用程序配置文件:C:\ Users \Sven \documents\visual studio 2010 \Projects \\ \\ DuplexDemo \CustomerService2 \ bin \Debug \CustomerService2.dll.config
日志:使用主机配置文件:
日志:使用C:\ Windows \Microsoft®中的机器配置文件\ Framework64\v4.0.21006\config\machine.config。
日志:尝试下载新的URL文件:/// C:/ Users / Sven / documents / visual studio 2010 / Projects / DuplexDemo / CustomerService2 / bin / Debug / CustomerService2.dll。
错误:无法完成程序集的设置(hr = 0x8007000b)。探测终止。


现在我已经改变了平台,服务库就不再运行了。所以现在我被困住了,我寻求一些解决方案。

有人能告诉我发生了什么吗?
不要认为代码有错误,因为它都是普通的WCF并且在它之前工作了。

请帮帮我


访问我的博客,了解更多有趣的WCF主题:http://www.mshelp.be

解决方案

<跨度风格=" font-family: '的Segoe UI', '很好的可读性',宋体,Arial字体,黑体,无衬线;字体大小:13像素;颜色:#333333;行高:16px"> C:\Windows\Microsoft.NET\Framework64\v4.0.21006\config\machine.config <。 / span>


 


你的
服务主机正在使用64位框架.x86不会在其中运行。


Hello

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.

Please help me out


Visit my blog for more interesting WCF topics: http://www.mshelp.be

解决方案

C:\Windows\Microsoft.NET\Framework64\v4.0.21006\config\machine.config.

 

Your service host is using the 64bit framework.  x86 won't run in it.


这篇关于System.BadImageFormatException - 无法解决它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆