C# 尝试加载一个程序,但 VS 安装时出现格式不正确的异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12482981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 23:23:59  来源:igfitidea点击:

an attempt was made to load a program with an incorrect format exception going away with VS installation

c#visual-studio-2010dllimport

提问by stack_pointer is EXTINCT

I've designed a C# Windows appln which also calls internally some functions [imported from C++ DLL through DllImport()]

我设计了一个 C# Windows appln,它也在内部调用一些函数[通过 DllImport() 从 C++ DLL 导入]

My C++ code is built as .DLL in Win32 platform whereas my C# is built as "Any CPU" platform.

我的 C++ 代码在 Win32 平台中构建为 .DLL,而我的 C# 构建为“任何 CPU”平台。

When I run the .EXE (C#) in my test machine, I face an error as

当我在我的测试机器上运行 .EXE (C#) 时,我面临一个错误

an attempt was made to load a program with an incorrect format exception from hresult 0x8007000B

尝试从 hresult 0x8007000B 加载具有不正确格式异常的程序

However, this error is not faced if I install VSS 2010 in my machine and then run the EXE.

但是,如果我在我的机器上安装 VSS 2010 然后运行 ​​EXE,则不会遇到此错误。

1) Reason for this error? 2) why is the error not observed when VSS is installed?

1)这个错误的原因?2)为什么安装VSS时没有观察到错误?

I've used Win7 OS(64bit) to build the .EXE (C#) in AnyCPUplatform which in turn depends on a DLL (C++ Dll imported in C# using DllImport) built in Win32

我已经使用 Win7 OS(64 位)在AnyCPU平台上构建 .EXE(C#),后者又依赖于Win32 中构建的 DLL(使用 DllImport 在 C# 中导入的 C++ Dll)

回答by Rob Allen

This is almost always because you are calling 32bit code from 64bit dll/exe,etc or a 64bit dll from a 32bit dll. What happens if you build the c# for x86? It will still run on 64bit.

这几乎总是因为您从 64 位 dll/exe 等调用 32 位代码或从 32 位 dll 调用 64 位 dll。如果为 x86 构建 c# 会发生什么?它仍将在 64 位上运行。