我在64位系统上调用32位非托管DLL的函数.我得到的是:
BadImageFormatException:尝试加载格式不正确的程序.(HRESULT异常:0x8007000B)
起初,我将我的项目设置为Any CPU平台,因此我将它们都更改为x86,但此错误仍在发生.这真的是我所知道的唯一解决方案.
DLL没有损坏或任何东西,因为我可以将它们与其他程序一起使用(我没有源代码).我想也许它没有找到依赖,但我检查了,他们都在那里.另外,DllNotFoundException在这种情况下不会抛出一个吗?
我还可以做些什么?在您说"使用64位非托管DLL"之前,让我指出没有一个.;)
我有两个项目,ProjectA和ProjectB. ProjectB是一个控制台应用程序,依赖于ProjectA.昨天,一切都运转良好,但今天突然我跑了,ProjectB我得到了这个:
BadImageFormatException未处理:
无法加载文件或程序集"ProjectA,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null"或其依赖项之一.尝试加载格式不正确的程序.
两者都只是常规项目,不依赖于任何其他非.Net项目.两者都是.Net - 没有本机代码,也没有P/Invoke.我有其他项目依赖ProjectA并仍然工作得很好.
我尝试过的事情:
但我仍然得到同样的错误.我不知道我做了什么导致这个,也不知道如何解决它.有任何想法吗?
有关可能导致此异常的原因的任何想法?
我有一个webservice proj,当我加载我得到的链接
无法加载文件或程序集"Interop.DIB"或其依赖项之一.尝试加载格式不正确的程序.
异常详细信息:System.BadImageFormatException:无法加载文件或程序集"Interop.DIB"或其依赖项之一.尝试加载格式不正确的程序.
内部例外:
[BadImageFormatException:无法加载文件或程序集"Interop.DIB"或其依赖项之一.试图加载格式不正确的程序.]
[ConfigurationErrorsException:无法加载文件或程序集"Interop.DIB"或其依赖项之一.试图加载格式不正确的程序.]
[HttpException(0x80004005):无法加载文件或程序集"Interop.DIB"或其依赖项之一.试图加载格式不正确的程序.]
版本信息:
Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.272
在VS中进行调试时,在VS中启动调试时会引发错误.
错误如下:
Could not load file or assembly 'p4dn, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.BadImageFormatException: Could not load file or assembly 'p4dn, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt …Run Code Online (Sandbox Code Playgroud) 我的应用程序编译正常,但我得到以下运行时错误:
System.IO.FileNotFoundException was unhandled
HResult=-2147024770
Message=Could not load file or assembly {Wrapper} or one of its dependencies. The specified module could not be found.
Run Code Online (Sandbox Code Playgroud)
调用Application中对Wrapper的引用看起来是正确的.Wrapper dll存在于正确的位置.
这个项目用于在别人的系统上构建和运行,我看过几次.该人/计算机不再可用.自上次成功构建和运行以来,某些依赖项的某些路径已发生更改,我已修复了与此相关的所有编译错误.
只是为了澄清我的项目结构:

Digraph G
{
App [ label = "My C# Application"]
Wrapper [ label = "C++/CLI Wrapper"]
Lib [ label = "C++ Library"]
Dll [ label = "My helper C# DLL"]
CDep [ label = "Series of deep C++ dependencies managed \n by CMake for Lib, hard coded relative paths for Wrapper."]
App->Wrapper->Lib->CDep; …Run Code Online (Sandbox Code Playgroud) 我正在构建一个仅64位的Web应用程序(AssemblyA)并引用我已经构建的另一个应用程序,它也是64位(AssemblyB).
当我添加AssemblyB作为引用时AssemblyA,我在Visual Studio中得到以下编译错误:
ASPNETCOMPILER无法加载文件或程序集"AssemblyB"或其依赖项之一.尝试加载格式不正确的程序.
我的应用程序的平台目标设置都设置为x64,两个Target Framework设置都是.Net Framework 4.6和Prefer 32bit is unchecked.
我尝试引用AssemblyBin的每个依赖引用AssemblyA,确保所有依赖引用的版本相同.
我使用过这个问题:如何确定.NET程序集是为x86还是x64构建的?确认所有引用的程序集是MSIL或AMD64.
我使用了aspnet_compiler.exe命令行工具并errorstack启用了选项,并获得了以下堆栈跟踪:
[BadImageFormatException]:无法加载文件或程序集"AssemblyB"或其依赖项之一.尝试加载格式不正确的程序.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,Boolean throwOnFileNotFound,Boolean forIntro spection,Boolean suppressSecurityChecks)
在System.Reflection.RuntimeAssembly.nLoad(的AssemblyName文件名,字符串的代码库,证据assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark&S tackMark,IntPtr的pPrivHostBinder,布尔throwOnFileNotFound,布尔forIntros pection,布尔suppressSecurityChecks)
在System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(的AssemblyName assemblyRef,证据assemblySecurity,RuntimeAssembly reqAssembly,StackCrawlMark&stackMark,IntPtr的pPrivHostBinder,布尔throwOnFileNotFound,布尔forIntrospection,布尔suppressSecurityChecks)
在System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,Evidence assemblySecurity,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,Boolean forIntrospection)
在System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,Evidence assemblySecurity,StackCrawlMark&stackMark,Boolean forIntrospection)
在System.Reflection.Assembly.Load(String assemblyString)
在System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName,Boolean starDirective)
[ConfigurationErrorsException]:无法加载文件或程序集"AssemblyB"或其依赖项之一.尝试加载格式不正确的程序.
在System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName,Boolean starDirective)
在System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomain …
在尝试从我的项目添加*.dll"AWSREMOTELIB"时,我遇到了这个问题......

这BadFormatException是什么意思?
c# ×5
.net ×2
exception ×2
32-bit ×1
64-bit ×1
asp.net ×1
c++-cli ×1
cmake ×1
compilation ×1
dependencies ×1
pinvoke ×1
web-services ×1