.Net程序集加载问题期间的BadImageFormatException

Geo*_*ge2 19 .net c# asp.net iis visual-studio-2010

当我尝试访问IIS 7.0中的网站(使用Windows Server 2008上的VSTS 2010 + .Net 4.0开发)中的页面(default.aspx)时,我遇到以下错误消息.有什么想法有什么不对?BadImageFormatException是什么意思?

顺便说一句:我运行Windows Server 2008 64位(不是R2)并且还没有激活Windows Server 2008,它可能是根本原因吗?

[BadImageFormatException: Could not load file or assembly 'test.foo' or one of its dependencies. Try to load bad formatted program. ]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +567
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +192
   System.Reflection.Assembly.Load(String assemblyString) +35
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +118

[ConfigurationErrorsException: Could not load file or assembly 'test.foo' or one of its dependencies.  Try to load bad formatted program. ]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11392147
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +484
   System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +127
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +334
   System.Web.Compilation.BuildManager.CallPreStartInitMethods() +280
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1087

[HttpException (0x80004005): Could not load file or assembly 'test.foo' or one of its dependencies.  Try to load bad formatted program. ]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11524352
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4782309

Abe*_*bel 16

BadImageFormatException可以找到程序集文件时引发,但它不是正确的程序集,或者已损坏.例如,如果您将文件FTP到服务器并且传输被中断,则DLL文件可能仅部分传输,从而导致发生此错误.

在64位与32位上:当您使用P/Invoke或COM Interop时,一些博主报告切换到特定的目标编译可能有助于您的情况.这意味着:如果你使用32位dll进行交互,请确保编译x86,强制它在WoW32下运行,否则你将收到此异常.此修复程序在此处此处得到确认.

或者,您可以通过运行以下命令将整个系统设置为默认的32位:

Ldr64.exe setwow

Framework64目录.

常见的解决方案是重建文件,或者至少重新发布它.


GHC*_*GHC 9

我在将32位DLL部署到运行IIS 7的64位服务器上时得到了这个.

要修复它,我必须在我的应用程序池的高级设置中将"启用32位应用程序"设置为True.