2010-08-29 26 views
18

当我尝试访问IIS 7.0中的网站(使用Windows Server 2008上的VSTS 2010 + .Net 4.0开发)中的页面(default.aspx)时,遇到以下错误信息。任何想法有什么不对?什么意思 BadImageFormatException?在.Net程序集加载问题期间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 
+1

我认为你的程序集名称缺少“.dll”。请提供代码片段。 – 2010-08-29 14:33:28

+3

64位/ 32位不匹配?你是否为特定的平台编译你的程序集? – Alex 2010-08-29 14:38:39

+0

“我认为你的程序集名称缺少”.dll“,请提供代码片段。” - 从堆栈跟踪中,我认为所有的代码堆栈跟踪都不在我自己的代码中,似乎.Net自己的代码?我需要提供哪些.dll文件,以及为了分析此问题需要哪些代码段? – George2 2010-08-29 14:42:01

回答

15

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

64位vs 32位:当您使用P/Invoke或COM Interop时,some blogger reports切换到特定的目标编译可能有助于您的情况。这意味着:如果你使用32位DLL进行接口,请确保编译为x86,迫使它在WoW32下运行,否则会收到此异常。此修复程序是confirmed herehere。从Framework64目录

 
Ldr64.exe setwow 

或者,你可以设置你的整个系统运行命令默认32位。

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

+0

你的意思是test.foo.dll本身已损坏或其他系统DLL? – George2 2010-08-29 14:44:01

+1

@ George2:我的意思是test.foo.dll已损坏,但看到我的新笔记在32位与64位,这可能看起来反直觉。 – Abel 2010-08-29 14:47:22

+0

感谢您的更新@Abel,你的意思是我应该重建解决方案到64位平台(因为我的Windows Server 2008是64位)? – George2 2010-08-29 14:48:14

2

您的网站是否使用DefaultAppPool? 如果是的话,试试你的网站的应用程序池设置的ASP.NET 4.0版, 或者,如果您使用的是自定义的应用程序池,验证它是否运行.NET Framework 4.0

+0

我正在使用新的应用程序池。我将它设置为使用.Net 4.0 Framework并使用集成模式。有任何想法吗? – George2 2010-08-29 14:43:23

+0

这个问题可能是由于我的Windows Server 2008未激活导致的(我还没有输入许可证号码)? – George2 2010-08-29 14:50:38

+1

您正在用哪个平台构建您的解决方案?任何CPU? 86? 我不认为这是一个激活问题。 您是否在使用任何第三方? – sagie 2010-08-29 14:54:28

6

部署到64位服务器上运行32个的DLL文件,当我刚刚得到这个IIS 7

要解决它,我必须设置“启用32位应用程序”我的应用程序的高级设置为True池。

+0

这就是为了我,谢谢+1 – Lee 2017-09-28 13:59:29