IIS 7.5修复试图加载一个不正确的格式问题的程序?

我有一个exception的问题抛出一个exception“试图加载程序格式不正确”的错误? 我在同一个IIS服务器上有两个相同的网站,我的构buildconfiguration适用于其中的一个,但不是其他的。

我的C#MVC 2 Web应用程序可以部署到驻留在同一个IIS 7.5 Web服务器(x64)上的两个网站。 一个是活动站点(使用发布configuration部署),第二个是testing站点(使用为此项目创build的新Betaconfiguration部署)。 两个项目的代码都是一样的。 他们有不同的构buildconfiguration,但configuration内的设置是相同的。

将发布configuration部署到默认网站/ my_app完美。

将Betaconfiguration部署到Beta / my_app部署,但是当我加载站点(任何页面)时,我得到不正确的格式exception。

我不明白为什么使用完全相同的configuration设置进行部署将适用于一个网站,而不是另一个(在同一个networking服务器上)。 我的服务器+开发机器是64位,并且这两个网站都有相同的应用程序池设置(.NET 4,集成)。

我怎样才能find/解决这个问题? 最好不必为每个站点设置不同的configuration。 而且最好不用改变发行configuration,因为这是工作,我不想冒险改变它。

这两个网站是:

Default Website/my_app Beta/my_app 

发布的configurationpipe理器具有以下设置:

发布构建配置

testing版的configurationpipe理器具有完全相同的设置:

测试版本配置

例外是:

 Could not load file or assembly 'MyApp.Domain.Model' or one of its dependencies. An attempt was made to load a program with an incorrect format. Stack Trace: [BadImageFormatException: Could not load file or assembly 'MyApp.Domain.Model' or one of its dependencies. An attempt was made to load a program with an incorrect format.] 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) +123 [ConfigurationErrorsException: Could not load file or assembly 'MyApp.Domain.Model' or one of its dependencies. An attempt was made to load a program with an incorrect format.] System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11479520 System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +484 System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +79 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 'MyApp.Domain.Model' or one of its dependencies. An attempt was made to load a program with an incorrect format.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11612256 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4842149 

我已经看到有关于“试图加载一个格式不正确的程序”的问题有多个问题,但我不认为这是重复的。 这是一个独特的情况,configuration在一个站点上工作正常,但不在另一个站点上使用相同的configuration设置和相同的Web服务器。

发现问题 – 解决方法是configuration两个AppPools:

  • 默认网站/ my_app正在使用DefaultAppPool,其中启用32位应用程序为TRUE
  • Beta / my_app – > BetaAppPool正在使用启用32位应用程序是FALSE

更改BetaAppPool以将启用32位应用程序设置为TRUE已解决此问题。

解决scheme是由@Rick发现在这个问题上: C#entity framework4公共语言运行时检测到一个无效的程序错误?

您有一个x86 dll被放置在您的x64部署位置。

不要这样做。 它不起作用。