我有一個不尋常的問題引發異常「試圖加載程序格式不正確」錯誤?我在同一個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
發佈配置管理器具有以下設置:
的測試配置管理器具有完全相同的設置:
唯一的例外是:
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服務器。
會發生什麼,當你與卡西尼跑的? – Illuminati