Avi*_*hen 38 c# badimageformatexception
我在c#中有一个使用c ++库和一些dll的项目.当我运行它时效果很好.
该库是Awesomium,包含c ++库和c#包装器
当我从ASP.NET MVC 4项目创建对该项目的引用时,我收到以下错误:
异常详细信息:System.BadImageFormatException:无法加载文件或程序集'file:/// D:\ Projects\Development\ProGamers\GamingSite\bin\avcodec-52.dll'或其依赖项之一.该模块应该包含一个程序集清单.
我试过的事情:
应对dll,但它仍然不起作用(该文件存在).
在GAC中注册它但我在那里遇到了同样的错误.
确保使用.NET Framework 4.0(而不是客户端配置文件)
2个具有相同dll/exe名称的文件导致冲突 - 我没有.
将解决方案的平台更改为AnyCPU/Mixed Platforms.
堆栈跟踪:
[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
Run Code Online (Sandbox Code Playgroud)
swd*_*dev 40
我发现,我在目标.NET Framework中使用了不同的InstallUtil.我正在构建一个.NET Framework 4.5,同时如果我使用的是.NET Framework 2.0版本,则会出现错误.为我的目标.NET Framework使用正确的InstallUtil,解决了这个问题!
Dav*_*yon 12
BadImageFormatException
根据我的经验,几乎总是与x86和x64编译的程序集有关.听起来你的C++程序集是为x86编译的,你在x64进程上运行.那是对的吗?
而不是AnyCPU/Mixed
用作平台.尝试手动将其设置为,x86
然后查看它是否会运行.
希望这可以帮助.
首先尝试使用 ILSpy 等反编译器打开该文件,您的 dll 可能已损坏。我在一个在线网站上遇到了这个错误,当我下载 dll 并尝试打开它时,它已损坏,可能是通过 ftp 上传它时发生了一些错误。
归档时间: |
|
查看次数: |
88098 次 |
最近记录: |