c# - Visual Studio MVC 平台 - x86 和 x64?

标签 c# asp.net-mvc iis cpu-architecture

大约一个月前我们遇到了一个非常烦人的问题,我们可以在需要自动代码生成/脚手架的 MVC 项目中添加一个 Controller 。

我们今天发现这与平台有关。最初,它被设置为 Any CPU,这对我来说似乎是正确的设置。但是,我们将其设置为 x86,因为我们拥有的 Visual Studio 版本是 32 位,并且我们能够再次添加 Controller 。添加了一个 Controller ,构建,然后去查看应用程序,它给出了以下错误:

无法加载文件或程序集“仪表板”或其依赖项之一。试图加载格式不正确的程序。 说明:在执行当前 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

然后我们需要将其设置为 x64 或任何 CPU 以在浏览器中查看项目,但它会阻止我们再次添加 Controller 。

有谁知道我们应该使用什么设置?它是突然开始的,我们真的不想根据我们正在做的事情在平台之间进行交换和更改,因为它真的应该在任何 CPU 上工作吗?

最佳答案

如果您在 IIS 上运行站点,那么这可能就是您所缺少的:

enter image description here

如果您的应用程序是为 x86 构建的,则需要为您的应用程序池启用它。

关于c# - Visual Studio MVC 平台 - x86 和 x64?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29648081/

相关文章:

.NET WCF 服务引用使用服务器名称而不是 IP 地址,导致使用时出现问题

ios - IIS 是否重定向以匹配 url 大小写?

c# - 允许多角色成员身份的自定义 MVC AuthorizeAttribute

c# - Controller 类包含太多方法

iis - 使用 global.asax 有哪些替代方法?

c# - 流利的 Nhibernate 表达式来选择标记的枚举

asp.net-mvc - 将复选框值绑定(bind)到模型 mvc 中的列表

c# - 位图图形与 WinForm 控件图形

c# - 为什么 IL 设置这个值两次?

C# Visual Studio 2015 - 自动跳转到括号