C# 该模块应包含程序集清单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12226676/
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 22:31:09  来源:igfitidea点击:

The module was expected to contain an assembly manifest

c#badimageformatexception

提问by Aviran Cohen

I have a project in c# that uses c++ library and some dlls. When I run it it works great.

我在 C# 中有一个项目,它使用 C++ 库和一些 dll。当我运行它时,它工作得很好。

The library is Awesomium, contains both c++ library and c# wrappers

该库是Awesomium,包含 c++ 库和 c# 包装器

When I create reference to this project from my ASP.NET MVC 4 project I get the following error:

当我从我的 ASP.NET MVC 4 项目创建对这个项目的引用时,我收到以下错误:

Exception Details: System.BadImageFormatException: Could not load file or assembly 'file:///D:\Projects\Development\ProGamers\GamingSite\bin\avcodec-52.dll' or one of its dependencies. The module was expected to contain an assembly manifest.

异常详细信息:System.BadImageFormatException:无法加载文件或程序集“file:///D:\Projects\Development\ProGamers\GamingSite\bin\avcodec-52.dll”或其依赖项之一。该模块应包含程序集清单。

Things I've tried:

我尝试过的事情:

  1. Coping the dlls, but it still doesn't work (The file exists).

  2. Registering it in the GAC but I've got the same error there.

  3. Make sure using .NET Framework 4.0 (and not client profile)

  4. 2 files with the same dll/exe name causing conflict- I dont have it.

  5. Change the platform of the solutionto AnyCPU/Mixed Platforms.

  1. 处理 dll,但它仍然不起作用(文件存在)。

  2. 在 GAC 中注册它,但我在那里遇到了同样的错误。

  3. 确保使用 .NET Framework 4.0(而不是客户端配置文件)

  4. 2 个具有相同 dll/exe 名称的文件导致冲突- 我没有。

  5. 将解决方案的平台更改为 AnyCPU/Mixed Platforms。

Stack Trace:

堆栈跟踪:

[BadImageFormatException: Could not load file or assembly 'file:///D:\Projects\Development\ProGamers\GamingSite\bin\avcodec-52.dll' or one of its dependencies. The module was expected to contain an assembly manifest.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
   System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) +102
   System.Reflection.Assembly.LoadFrom(String assemblyFile) +34
   WebActivator.ActivationManager.Run() +190

[InvalidOperationException: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Could not load file or assembly 'file:///D:\Projects\Development\ProGamers\GamingSite\bin\avcodec-52.dll' or one of its dependencies. The module was expected to contain an assembly manifest..]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +550
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +90
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +135
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516

[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Could not load file or assembly 'file:///D:\Projects\Development\ProGamers\GamingSite\bin\avcodec-52.dll' or one of its dependencies. The module was expected to contain an assembly manifest..]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9850940
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +456

回答by Davin Tryon

BadImageFormatException, in my experience, is almost always to do with x86 versus x64 compiled assemblies. It sounds like your C++ assembly is compiled for x86 and you are running on an x64 process. Is that correct?

BadImageFormatException,以我的经验,几乎总是与 x86 与 x64 编译程序集有关。听起来您的 C++ 程序集是为 x86 编译的,并且您正在 x64 进程上运行。那是对的吗?

Instead of using AnyCPU/Mixedas the platform. Try to manually set it to x86and see if it will run after that.

而不是AnyCPU/Mixed用作平台。尝试手动将其设置为,x86然后查看它是否会运行。

Hope this helps.

希望这可以帮助。

回答by swdev

I found that, I am using a different InstallUtil from my target .NET Framework. I am building a .NET Framework 4.5, meanwhile the error occured if I am using the .NET Framework 2.0 release. Having use the right InstallUtil for my target .NET Framework, solved this problem!

我发现,我使用的 InstallUtil 与目标 .NET Framework 不同。我正在构建 .NET Framework 4.5,同时如果我使用的是 .NET Framework 2.0 版本,则会发生错误。为我的目标 .NET Framework 使用了正确的 InstallUtil,解决了这个问题!

回答by QMaster

I found another strange reason and i thought maybe another developer confused as me. I did run install.bat that created to install my service in developer Command Prompt of VS2010but my service generated in VS2012. it was going to this error and drives me to crazy but i try VS2012 Developer Command Prompttools and everything gone to be OK. I don't no why but my problem was solved. so you can test it and if anyone know reason of that please share with us. Thanks.

我发现了另一个奇怪的原因,我想也许另一个开发人员和我一样困惑。我确实运行了 install.bat 来在VS2010 的开发人员命令提示符中安装我的服务,但我的服务是在 VS2012 中生成的。它会出现这个错误并让我发疯,但我尝试了VS2012 开发人员命令提示符工具,一切正常。我不知道为什么,但我的问题解决了。所以你可以测试它,如果有人知道原因,请与我们分享。谢谢。

回答by Pandele Florin

Check if the manifest is a valid xml file. I had the same problem by doing a DOS copy command at the end of the build, and it turns out that for some reason I can not understand "copy" was adding a strange character (->) at the end of the manifest files. The problem was solved by adding "/b" switch to force binary copy.

检查清单是否是有效的 xml 文件。我在构建结束时执行 DOS 复制命令时遇到了同样的问题,结果证明由于某种原因我无法理解“复制”在清单文件的末尾添加了一个奇怪的字符 (->)。通过添加“/b”开关强制二进制复制解决了这个问题。

回答by BornToCode

First try to open the file with a decompiler such as ILSpy, your dll might be corrupt. I had this error on an online web site, when I downloaded the dll and tried to open it, it was corrupt, probably some error occurred while uploading it via ftp.

首先尝试使用反编译器(例如 ILSpy)打开文件,您的 dll 可能已损坏。我在一个在线网站上遇到此错误,当我下载 dll 并尝试打开它时,它已损坏,可能在通过 ftp 上传时发生了一些错误。

回答by itsho

I got the error in the following case:

我在以下情况下收到错误:

  1. A .NET EXE file (#1) was referencing another .NET EXE file (#2)
  2. I was trying to obfuscate EXE #2 with Themida
  3. when running the EXE #1 it was crashing with the error "The module was expected to contain an assembly manifest"
  1. .NET EXE 文件 (#1) 引用了另一个 .NET EXE 文件 (#2)
  2. 我试图用Themida混淆 EXE #2
  3. 运行 EXE #1 时,它因错误“该模块应包含程序集清单”而崩溃

I simply avoided the obfuscation and the error is gone. not a real solution, but at least I know what caused it...

我只是避免了混淆,错误就消失了。不是一个真正的解决方案,但至少我知道是什么导致了它......