我有一个不寻常的问题,抛出异常"尝试加载具有错误格式的程序"错误?我在同一台IIS服务器上拥有两个相同的网站,我的生成配置适用于其中一个,但不适用于另一个。
我的C# MVC 2 Web应用程序可以部署到同一台IIS 7.5 Web服务器(x64)上的两个网站。一个是现场网站(使用Release配置部署),第二个是Beta网站(使用专门为该项目创建的新Beta配置部署)。这两个项目的代码库相同。它们有不同的生成配置,但配置内部的设置是相同的。
将Release配置部署到Default Website/my_app中完美运行。
将Beta配置部署到Beta/my_app中可部署,但当我加载该网站(任何页面)时,会出现错误格式异常。
我无法理解为什么使用完全相同的配置设置在一个网站上能够正常工作,而在另一个网站上却无法正常工作(在同一台Web服务器上)。我的服务器和开发机都是64位的,两个网站都具有相同的应用池设置(.NET 4,集成)。
如何找到/修复此问题?最好不要为每个站点使用不同的配置设置。最好不要更改发布配置,因为那是有效的,我不想冒险更改它。
这两个网站是:
我的C# MVC 2 Web应用程序可以部署到同一台IIS 7.5 Web服务器(x64)上的两个网站。一个是现场网站(使用Release配置部署),第二个是Beta网站(使用专门为该项目创建的新Beta配置部署)。这两个项目的代码库相同。它们有不同的生成配置,但配置内部的设置是相同的。
将Release配置部署到Default Website/my_app中完美运行。
将Beta配置部署到Beta/my_app中可部署,但当我加载该网站(任何页面)时,会出现错误格式异常。
我无法理解为什么使用完全相同的配置设置在一个网站上能够正常工作,而在另一个网站上却无法正常工作(在同一台Web服务器上)。我的服务器和开发机都是64位的,两个网站都具有相同的应用池设置(.NET 4,集成)。
如何找到/修复此问题?最好不要为每个站点使用不同的配置设置。最好不要更改发布配置,因为那是有效的,我不想冒险更改它。
这两个网站是:
Default Website/my_app
Beta/my_app
发布版的配置管理器具有这些设置:
测试版的配置管理器具有完全相同的设置:
唯一的例外是:
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
我看到 Stack Overflow 上有多个问题问到“尝试使用不正确的格式加载程序”,但我认为这并不是一个重复的问题。这是一种独特的情况,配置在一个站点上运行良好,但在另一个站点上使用相同的配置设置和相同的 Web 服务器时无法正常工作。