【发布时间】: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