2015-04-15 95 views
1

我們有一個令人討厭的問題,大約一個月前開始,我們可以在需要自動生成代碼/腳手架的MVC項目中添加一個控制器。Visual Studio MVC平臺 - x86和x64?

今天我們發現它與平臺有關。最初,它被設置爲任何CPU,這對我來說似乎是正確的設置。但是,我們將它設置爲x86,因爲我們擁有的Visual Studio版本是32位,而且我們能夠再次添加控制器。添加了一個控制器,並構建並查看應用程序,並提供以下錯誤:

無法加載文件或程序集「儀表板」或其某個依賴項。試圖加載格式不正確的程序。 描述:執行當前Web請求期間發生未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。

異常詳細信息:System.BadImageFormatException:無法加載文件或程序集「Dashboard」或其某個依賴項。試圖加載格式不正確的程序。

Source Error: 


An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Dashboard' could not be loaded. 



WRN: Assembly binding logging is turned OFF. 
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. 
Note: There is some performance penalty associated with assembly bind failure logging. 
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. 



Stack Trace: 



[BadImageFormatException: Could not load file or assembly 'Dashboard' 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, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 
    System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +210 
    System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +242 
    System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +17 
    System.Reflection.Assembly.Load(String assemblyString) +35 
    System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +122 

[ConfigurationErrorsException: Could not load file or assembly 'Dashboard' 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) +12480704 
    System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +499 
    System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +131 
    System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +331 
    System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +148 
    System.Web.Compilation.BuildManager.ExecutePreAppStart() +172 
    System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151 

[HttpException (0x80004005): Could not load file or assembly 'Dashboard' or one of its dependencies. An attempt was made to load a program with an incorrect format.] 
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12601936 
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159 
    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12441597 

然後,我們需要將其設置爲64或任何CPU以查看在瀏覽器中的項目,但隨後停止我們再次加入控制器。

有誰知道我們應該使用什麼設置?它從藍色開始,我們不是真的想在平臺之間交換和改變,這取決於我們在做什麼,因爲它確實應該在任何CPU上工作。

+0

這與您的visual studio x86,x64,任何cpu設置無關。 我不知道它的方式,它是應用程序將被部署到的目標系統平臺,即Win7 x86或Win7x64或win2008服務器 – Legends

回答

4

如果你正在運行在IIS上的網站,那麼這可能是你錯過了什麼:

enter image description here

您需要啓用它爲您的應用程序池,如果你的應用程序是專爲86。

+0

是的,這樣做!非常感謝:) –

+0

這是有幫助的,但我認爲一個更好的解決方案是讓他的構建工作的64位。 – Rup

+0

@將「應用程序」保留爲內聯網站點,提供我們可以添加控制器等並無需前後查看,我們對此非常滿意。但是,如果有人想提供一個別人可能會用到的答案,那就太好了:) –