我遇到一个异常问题,抛出异常“尝试加载格式不正确的程序”错误?我在同一台 IIS 服务器上有两个相同的网站,我的构建配置适用于其中一个,但不适用于另一个。
我的 C# MVC 2 Web 应用程序可以部署到驻留在同一 IIS 7.5 Web 服务器 (x64) 上的两个网站。一个是实时站点(使用发布配置部署),第二个是测试站点(使用专门为此项目创建的新测试版配置部署)。这两个项目的代码库是相同的。它们具有不同的构建配置,但配置内的设置是相同的。
将发布配置部署到默认网站/my_app 效果很好。
将测试版配置部署到 Beta/my_app 部署,但是当我加载站点(任何页面)时,我收到格式错误的异常。
我无法理解为什么使用完全相同的配置设置进行部署适用于一个网站,但不适用于另一个网站(在同一网络服务器上)。我的服务器 + 开发计算机是 64 位,并且两个网站具有相同的应用程序池设置(.NET 4,集成)。
我怎样才能找到/解决这个问题?最好不必为每个站点设置不同的配置设置。最好不必更改发布配置,因为它正在工作,我不想冒险更改它。
这两个网站是:
Default Website/my_app
Beta/my_app
发布的配置管理器具有以下设置:
Beta 版的配置管理器具有完全相同的设置:
例外情况是:
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
我看到有多个问题询问“尝试加载格式不正确的程序”,但我不认为这是重复的。这是一种独特的情况,配置在一个站点上工作正常,但在另一个站点上使用相同的配置设置和相同的网络服务器则不行。