【发布时间】:2012-08-26 22:34:15
【问题描述】:
我有一个使用 c++ 库和一些 dll 的 c# 项目。当我运行它时效果很好。
库是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(而不是客户端配置文件)
Change the platform of the solution 到 AnyCPU/混合平台。
堆栈跟踪:
[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
【问题讨论】:
-
您能从与Assembly Binding log viewer 的绑定中获取日志吗?确保首先将设置设置为记录所有绑定。
-
Assembly.LoadFrom() 不能在 avcodec-52.dll 之类的 DLL 上工作,它不是 .NET 程序集。如果您不发布 sn-p,为什么您的代码会尝试像这样加载它是完全不清楚的。
-
Hans 我没有手动使用 Assembly,它在控制台应用程序中运行良好。只有当我从我的 ASP.NET 应用程序中引用它时才会出现问题。我做的唯一用途是引用 Awesomium dll。 awesomium.com
-
你能选择一个答案吗?什么解决了你的问题。您的问题解决了吗?
标签: c# badimageformatexception