无法加载文件或程序集“Microsoft.AspNet.Scaffolding.12.0”

本文关键字:Scaffolding AspNet Microsoft 加载 文件 程序集 | 更新日期: 2024-10-25 20:46:03

我正在尝试将我的 ASP.NET MVC项目部署到IIS 8.5.9600服务器。当我在VS 2015 pro中运行它时,一切都加载并运行良好。当我发布它或手动加载它时,我收到以下错误页面:

Server Error in '/' Application.
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. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
 Exception Details: System.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.
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 'Microsoft.AspNet.Scaffolding.12.0' 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 '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) +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 '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) +12496980
   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 '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) +12618692
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12458309

这是我的软件包列表:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
  <package id="bootstrap" version="3.0.0" targetFramework="net45" />
  <package id="EntityFramework" version="6.1.3" targetFramework="net45" />
  <package id="Foundation5.Core" version="5.5" targetFramework="net45" />
  <package id="Foundation5.MVC" version="2.0.550" targetFramework="net45" />
  <package id="iTextSharp" version="5.5.7" targetFramework="net45" />
  <package id="jQuery" version="1.10.2" targetFramework="net45" />
  <package id="jquery.datatables" version="1.10.7" targetFramework="net45" />
  <package id="jQuery.Validation" version="1.11.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.Identity.Core" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.Identity.EntityFramework" version="1.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.Identity.Owin" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" />
  <package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.2" targetFramework="net45" />
  <package id="Microsoft.Owin" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Cookies" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Facebook" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Google" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.MicrosoftAccount" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.OAuth" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Twitter" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
  <package id="Modernizr" version="2.6.2" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />
  <package id="Owin" version="1.0" targetFramework="net45" />
  <package id="Respond" version="1.2.0" targetFramework="net45" />
  <package id="WebGrease" version="1.5.2" targetFramework="net45" />
</packages>

最后是我的服务器应用程序日志所说的:

Event code: 3008 
Event message: A configuration error has occurred. 
Event time: 4/20/2016 11:29:54 AM 
Event time (UTC): 4/20/2016 3:29:54 PM 
Event ID: 95491a89c7bc498f9e24ae307bcb64d1 
Event sequence: 1 
Event occurrence: 1 
Event detail code: 0 
Application information: 
    Application domain: /LM/W3SVC/1/ROOT-1-131056397942263660 
    Trust level: Full 
    Application Virtual Path: / 
    Application Path: C:'inetpub'wwwroot'StarkCountyCourts'Web' 
    Machine name: STARKCOCP 
Process information: 
    Process ID: 3636 
    Process name: w3wp.exe 
    Account name: IIS APPPOOL'DefaultAppPool 
Exception information: 
    Exception type: ConfigurationErrorsException 
    Exception message: 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.
   at System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)
   at System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()
   at System.Web.Configuration.AssemblyInfo.get_AssemblyInternal()
   at System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig)
   at System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded)
   at System.Web.Compilation.BuildManager.ExecutePreAppStart()
   at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)
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.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
   at System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)

Request information: 
    Request URL: http://localhost/ 
    Request path: / 
    User host address: ::1 
    User:  
    Is authenticated: False 
    Authentication Type:  
    Thread account name: IIS APPPOOL'DefaultAppPool 
Thread information: 
    Thread ID: 7 
    Thread account name: IIS APPPOOL'DefaultAppPool 
    Is impersonating: False 
    Stack trace:    at System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)
   at System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()
   at System.Web.Configuration.AssemblyInfo.get_AssemblyInternal()
   at System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig)
   at System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded)
   at System.Web.Compilation.BuildManager.ExecutePreAppStart()
   at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException

无法加载文件或程序集“Microsoft.AspNet.Scaffolding.12.0”

我们的一位管理员发现这是由于应用程序池不允许 32 位应用程序引起的。在应用程序池中,单击"高级设置",将"启用 32 位应用程序"设置为 True。

好的 -

所以我知道这是一年前发布的 - 但从查看此页面的人数(在撰写本文时为 800 人)来看,我认为这是一个需要进一步澄清的问题。

我的应用程序在本地运行良好,但是当部署到托管服务器时,我会收到此错误:https://i.stack.imgur.com/ANCu7.png

因此,事实证明,默认情况下,任何本地 IIS 应用程序池都运行 64 位应用程序。您需要做的是更改该设置以 32 位运行应用程序。这就是我这边的样子:https://i.stack.imgur.com/DWxmY.png

需要在本地计算机 IIS 上进行这些更改,然后将应用发布并部署到托管服务器。

有一篇非常有用的文章,我无法发布链接(因为目前我没有足够的声誉点来发布 3 个链接),您可以通过此谷歌搜索找到它:How to Enable a 32-bit Application Pool in IIS 7 (Dedicated/VPS)

我通过从 Web 项目中的 Windows 文件夹探索中删除objbin文件夹来解决此问题。

重建我的项目后,文件夹和文件将再次重新生成,并且已修复。

所有以前的答案都可能是正确的。

我有同样的错误。发现程序集"Microsoft.AspNet.Scaffolding.12.0"的加载被 IIS 停止,因为端口已被使用。

我通过更改应用程序的端口(端口已被使用)解决了这个问题。

在将服务器上的 IIS 配置从 64 位>更改为 32 位之前,可能需要检查一下......