【问题标题】:Visual Studio MVC Platforms - x86 and x64?Visual Studio MVC 平台 - x86 和 x64?
【发布时间】:2015-04-15 10:42:01
【问题描述】:

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

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

无法加载文件或程序集“仪表板”或其依赖项之一。试图加载格式不正确的程序。 说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.BadImageFormatException:无法加载文件或程序集“仪表板”或其依赖项之一。试图加载格式不正确的程序。

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 或 Any CPU 才能在浏览器中查看项目,但它会阻止我们再次添加控制器。

有人知道我们应该使用什么设置吗?它一开始是出乎意料的,我们真的不想根据我们正在做的事情在平台之间进行交换和更改,因为它确实应该可以在任何 CPU 上运行?

【问题讨论】:

  • 这与你的visual studio x86、x64、任何cpu设置无关。我理解它的方式,它是将应用程序部署到的目标系统平台,即 Win7 x86 或 Win7x64 或 win2008 服务器

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


【解决方案1】:

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

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

【讨论】:

  • 是的,做到了!非常感谢:)
  • 这很有帮助,但我认为更好的解决方案是让他的构建适用于 64 位。
  • @Rup “应用程序”因为它是一个 Intranet 站点,只要我们可以添加控制器等并在不来回的情况下查看它,我们对此非常满意。但是,如果有人想提供其他人可能会使用的答案,那就太好了:)
  • 我同意使用 x64 会好得多,但如果您需要 Visual Studio 加载程序集以生成代码,这似乎很棘手,这似乎是他们正在做的事情。我不想进入“如何”或“为什么”。
猜你喜欢
  • 1970-01-01
  • 2014-09-10
  • 2011-08-24
  • 1970-01-01
  • 2017-06-11
  • 1970-01-01
  • 2013-07-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多