2011-07-18 55 views
38

我有一個不尋常的問題引發異常「試圖加載程序格式不正確」錯誤?我在同一個IIS服務器上有兩個相同的網站,我的構建配置適用於其中一個,但不適用於其他網站。我的C#MVC 2 web應用程序可以部署到駐留在同一IIS 7.5 Web服務器(x64)上的兩個網站。一個是活動站點(使用Release配置部署),第二個是測試站點(使用爲此項目創建的新Beta配置進行部署)。兩個項目的代碼都是一樣的。它們具有不同的構建配置,但配置中的設置是相同的。IIS 7.5修復試圖加載具有不正確格式問題的程序?

將發佈配置部署到默認網站/ my_app完美。

將beta配置部署到Beta/my_app部署,但是當我加載站點(任何頁面)時,我得到不正確的格式異常。

我不明白爲什麼使用完全相同的配置設置進行部署只適用於一個網站,而不適用於另一個網站(在同一個網絡服務器上)。我的服務器+開發機器是64位,並且這兩個網站都有相同的應用程序池設置(.NET 4,集成)。

我該如何找到/解決這個問題?最好不必爲每個站點設置不同的配置。最好不用修改發行版配置,因爲這是可行的,我不想冒險改變它。

兩個網站分別是:

Default Website/my_app 
Beta/my_app 

發佈配置管理器具有以下設置:

release build configuration

的測試配置管理器具有完全相同的設置:

beta build configuration

唯一的例外是:

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 

我已經看到了有關於SO詢問「試圖加載程序格式不正確」多的問題,但我不認爲這是重複的。這是一個獨特的情況,配置可以在一個站點上正常工作,但不會在另一個站點上使用相同的配置設置和相同的Web服務器。

+0

會發生什麼,當你與卡西尼跑的? – Illuminati

回答

71

發現問題 - 該解決方案是在方式使得兩個AppPools配置:

  • 默認網站/ my_app應用是使用默認應用,其中使32位應用程序是TRUE
  • 貝塔/ my_app應用 - > BetaAppPool使用啓用32位應用程序是假的

更改BetaAppPool設置啓用32位應用程序爲TRUE已解決此問題。

解決方案是在這個問題上發現@Rick:C# Entity Framework 4 Common Language Runtime detected an invalid program error?

+0

只是添加到這個答案 - 我也通過網絡應用程序,並確保它可以運行在64位,然後在兩個AppPools上設置啓用32位應用程序爲false - 它的工作原理和性能更好 –

+0

感謝您!我在查看http://blogs.msdn.com/b/sayanghosh/archive/2007/04/21/solution-to-could-not-load-file-or-assembly-or-one-of-its-依賴關係-access-is-denied.aspx,但事實證明,這只是這個設置......謝謝! – juFo

3

您有一個x86 dll被丟棄在您的x64部署位置。

不要這樣做。它不起作用。

+0

那麼爲什麼它可以用於我的版本構建配置,該配置被部署到完全相同的x64 windows 2008服務器上? –

+0

我不知道你對你的配置做了什麼,但是如果你通過二進制文件,你會發現你設法在那裏放錯了二進制文件。 – Joshua

+0

@Joshua如何找到'x64部署位置'在哪裏? – Lijo

相關問題