代码之家  ›  专栏  ›  技术社区  ›  George2

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

  •  19
  • George2  · 技术社区  · 16 年前

    当我尝试访问页面时(默认.aspx)在iis7.0的一个网站(在windowsserver2008上使用vsts2010+.net4.0开发)中,我遇到了以下错误消息。有什么问题吗?什么意思

    顺便说一句:我运行的是64位的WindowsServer2008(不是R2),还没有激活WindowsServer2008,这可能是根本原因吗?

    [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 回复  |  直到 9 年前
        1
  •  18
  •   Abel    16 年前

    BadImageFormatException

    在64位和32位上:当您使用P/Invoke或COM Interop时, some blogger reports x86 confirmed here 和 here

    Ldr64.exe setwow
    

    从 Framework64

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

        2
  •  10
  •   GHC    11 年前

    为了解决这个问题,我必须在我的应用程序池的高级设置中将“启用32位应用程序”设置为True。

        3
  •  3
  •   sagie    16 年前

    您的网站是否使用DefaultAppPool? 如果是,请尝试将网站的应用程序池设置为ASP.Net v4.0, 或者,如果您使用的是自定义应用程序池,请验证它是否运行.net framework 4.0

        4
  •  0
  •   Jon Breytman    7 年前

    Import-Module WebAdministration
    Set-ItemProperty IIS:\AppPools\DefaultAppPool\ -Name enable32BitAppOnWin64 -Value $true