无法加载文件或程序集 'Microsoft.AspNet.Scaffolding.12.0' 或其依赖项之一

Could not load file or assembly 'Microsoft.AspNet.Scaffolding.12.0' or one of its dependencies

从源代码控制中拉下旧项目并尝试 运行 后,我收到以下错误:

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.AspNet.Scaffolding.12.0
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Microsoft.AspNet.Scaffolding.12.0 | Domain ID: 3
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/PROJECTS/C.App/
LOG: Initial PrivatePath = C:\PROJECTS\C.App\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\PROJECTS\C.App\web.config
LOG: Using host configuration file: C:\Users\C\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/C/AppData/Local/Temp/Temporary ASP.NET Files/vs/566b0c0d/a2911b5/Microsoft.AspNet.Scaffolding.12.0.DLL.
LOG: Attempting download of new URL file:///C:/Users/C/AppData/Local/Temp/Temporary ASP.NET Files/vs/566b0c0d/a2911b5/Microsoft.AspNet.Scaffolding.12.0/Microsoft.AspNet.Scaffolding.12.0.DLL.
LOG: Attempting download of new URL file:///C:/PROJECTS/C.App/bin/Microsoft.AspNet.Scaffolding.12.0.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

可能是什么原因造成的?

我试过:

我正在使用 IISExpress;这是本地主机,当我 运行 处于发布和调试模式的应用程序时出现错误(经典黄色 ASP.Net 错误)。

完整堆栈跟踪:

[BadImageFormatException: Could not load file or assembly 'Microsoft.AspNet.Scaffolding.12.0' 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) +225
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +110
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +22
   System.Reflection.Assembly.Load(String assemblyString) +34
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +48

[ConfigurationErrorsException: Could not load file or assembly 'Microsoft.AspNet.Scaffolding.12.0' 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) +729
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +247
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +157
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +226
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +73
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +321
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +170
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +734

[HttpException (0x80004005): Could not load file or assembly 'Microsoft.AspNet.Scaffolding.12.0' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +525
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +118
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +708

请仔细检查 64 位 IISExpress 是否在 Visual Studio

中 运行

转到: 工具 -> 选项 -> 项目和解决方案 -> Web 项目

取消选中 "Use 64-bit IIS Express"

检查 packages.config 中 Microsoft.AspNet.Scaffolding 的版本,看看它是否与您的 DLL 版本不同。如果版本不正确,请更正 packages.config 中的版本。