IIS 7.5 修复尝试加载格式不正确的程序问题?
我遇到一个异常问题,抛出异常“尝试加载格式不正确的程序”错误?我在同一台 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
发布版的配置管理器具有以下设置:
测试版的配置管理器具有完全相同的设置设置:
例外是:
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
我发现有多个问题询问“An attempts was加载格式不正确的程序”但我不相信这是重复的。这是一种独特的情况,配置在一个站点上工作正常,但在另一个站点上使用相同的配置设置和相同的网络服务器则不行。
I have a unusual problem throwing an exception "An attempt was made to load a program with an incorrect format" error? I have two identical websites on the same IIS server and my build configuration works for one of them but not the other.
My C# MVC 2 web app can deployed to two websites that reside on the same IIS 7.5 webserver (x64). One is the live site (deployed using Release configuration), the second is the beta site (deployed using a new Beta configuration created just for this project). The codebase for both projects is the same. They have different build configurations, but the settings inside the configurations are identical.
Deploying the release configuration to Default Website/my_app works perfectly.
Deploying the beta configuration to Beta/my_app deploys, but when I load the site (any page) I get the incorrect format exception.
I cannot understand why deploying with the exact same config settings would work for one website but not another (on the same webserver). My server + dev machines are 64 bit, and both websites have the same app pool settings (.NET 4, integrated).
How can I find/fix this problem? Preferably without having to have different config settings for each site. And preferably without having to change the release config since that is working and I don't want to risk changing it.
The two websites are:
Default Website/my_app
Beta/my_app
The configuration manager for release has these settings:
The configuration manager for beta has the exact same settings:
The exception is:
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
I've seen that there are multiple questions on SO asking about "An attempt was made to load a program with an incorrect format" but I do not believe this to be a duplicate. This is a unique situation with the config working fine on one site but not on another using the same config settings and the same webserver for both.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发现问题 - 解决方案是配置两个 AppPool 的方式:
更改 BetaAppPool 以将“启用 32 位应用程序”设置为 TRUE 已修复此问题。
@Rick 在这个问题上找到了解决方案:C# 实体框架 4 公共语言运行时检测到无效程序错误?
Found the problem - The solution is in the way that the two AppPools are configured:
Changing BetaAppPool to set Enable 32-Bit applications to TRUE has fixed this problem.
Solution was found by @Rick on this question: C# Entity Framework 4 Common Language Runtime detected an invalid program error?