简体   繁体   English

自托管服务时出现System.BadImageFormatException

[英]System.BadImageFormatException while self-hosting service

I have used one DLL which works perfectly fine when used in console application. 我使用了一个在console应用程序中工作时完全正常的DLL But when I use this in a self-hosted WcfService , then it gives the error System.BadImageFormatException . 但是,当我在自托管的WcfService中使用它时,它将给出错误System.BadImageFormatException

What could be the reason, and what is the solution for it? 原因可能是什么?解决方案是什么?

The most likely reason is an incorrectly set platform target. 最可能的原因是平台目标设置不正确。 The bitness of the DLL and the one of the executable must match as you can't load a 64-bit DLL into a 32-bit process (or vice-versa). DLL的位和可执行文件之一必须匹配,因为您无法将64位DLL加载到32位进程中(反之亦然)。

Try setting the platform target of the DLL to AnyCPU (Note that the platform target needs to be set per build configuration separately). 尝试将DLL的平台目标设置为AnyCPU(请注意,需要针对每个构建配置分别设置平台目标)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM