Could not load file or assembly 'Microsoft.AspNet.Scaffolding.12.0'

1

I am trying to deploy my ASP.NET MVC project to a IIS 8.5.9600 server. When I run it inside VS 2015 pro, everything loads and runs just fine. When I publish it or load it manually I get the following error page:

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

Here is my package list:

<?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>

And finally here is what my server applog says:

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

)

c#
asp.net
asked on Stack Overflow Apr 20, 2016 by James Worley

4 Answers

4

One of our administrators discovered this is caused by the Application Pool not allowing 32-Bit applications. In the Application Pool, click Advanced Settings, set "Enable 32-Bit Applications" to True.

answered on Stack Overflow Apr 20, 2016 by James Worley
2

I solved this problem by delete the obj and bin folder from windows folder explore in my web project.

After rebuild my project, the folder and files will regenerate again, and it's fixed.

answered on Stack Overflow Dec 27, 2016 by au.tw
2

Okay - so I know this was posted a year ago - but judging by the number of people who viewed this page (800 strong at the time of this writing) I figured this to be an issue in need of more clarification.

My application was running fine locally but when deployed to the hosting server I would get this error: https://i.stack.imgur.com/ANCu7.png

So it turns out that by default any local IIS application pool runs 64 bit apps. What you need to do is to change that setting to run your application in 32 bits. This is what it looks like on my end: https://i.stack.imgur.com/DWxmY.png

You need to make these changes on your local machine IIS - then publish and deploy your app to the hosting server.

There is a very helpful article that I could not post the link to (as at the moment I do not have enough reputation points to post 3 links) you can find it by doing this google search: How to Enable a 32-bit Application Pool in IIS 7 (Dedicated/VPS)

answered on Stack Overflow May 7, 2017 by Southern Fire
0

All previous answers might be correct.

BUT

I had the same error. Found out that the loading of the assembly 'Microsoft.AspNet.Scaffolding.12.0' was stopped by IIS because the port was already used.

I solved the problem by changing the port of the application (the port was already use).

Might want to check that before changing IIS config from 64bits -> 32bits on your server...

answered on Stack Overflow Feb 15, 2019 by Igor Beaufils

User contributions licensed under CC BY-SA 3.0