当我尝试访问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
3 回答
在找到程序集文件时引发
BadImageFormatException
,但它不是正确的程序集,或者已损坏 . 例如,如果您将文件FTP到服务器并且传输被中断,则DLL文件可能仅部分传输,从而导致发生此错误 .在64位与32位上:当您使用P / Invoke或COM Interop时,切换到特定目标编译的some blogger reports可能有助于您的情况 . 这意味着:如果你使用32位dll进行接口,请确保编译为
x86
,强制它在WoW32下运行,否则你将收到此异常 . 此修复程序是confirmed here和here .或者,您可以通过运行以下命令将整个系统设置为默认的32位:
来自
Framework64
目录 .常见的解决方案是重建文件,或者至少重新发布它 .
我在将32位DLL部署到运行IIS 7的64位服务器上时得到了这个 .
要修复它,我必须在我的应用程序池的高级设置中将“启用32位应用程序”设置为True .
您的网站是否使用DefaultAppPool?如果是这样,请尝试将您的网站的应用程序池设置为ASP .Net v4.0,或者如果您使用的是自定义应用程序池,请验证它是否正在运行.net framework 4.0