WCF service library : BadImageFormatException with 32 bit dll

十年热恋 提交于 2019-12-11 03:57:59

问题


My project Structure looks like this:

 myApp 
 -->WCFSerLib (Any CPU Deafult application) 
 -->ClassLib1 (Any CPU)
 -->ClassLib2 (x86)

When I try to execute my application Unfortuantely am getting this below error.

 System.BadImageFormatException was unhandled by user code

Is there anyway such that I can achieve the above?

Thanks


回答1:


If I guess right than you are trying to use an x86 dll on a x64 mashine. With AnyCPU the .net framework will use the currient architecture automatically.

So your application runs as a x64 Application which tries to load a x86 libary which failes. So you have two options:

  • Set the target architeture to x86
  • Add/create a x64 libary

If you have both verions (x86/x64) somewhere in you envireonment variable the operation system will choos the correct one automatically.




回答2:


I suppose that you are running your application on a x64 system.
Mixing the Platform Type in that way will cause the BFE when the WCFService Library or the ClassLib1 call methods in ClassLib2 because the first two run as 64bit processes while the latter is forced to run in x86 mode.

You should set the same platform type on every project.
Of course, the WCFService library supports only AnyCPU, so it make sense to use, for every project, the AnyCPU platform type.

If your ClassLib2 requires the use of a 32bit library (winscard.dll) and there is no 64bit version of that library, then, I think you should use a WCF Service Application instead of a Service Library. See this question




回答3:


Thank you guys,

problem was with winscard.dll it uses Handles which are Int32 .all I changed is replacing the Int32 with Int64.



来源:https://stackoverflow.com/questions/13120433/wcf-service-library-badimageformatexception-with-32-bit-dll

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!