Sometimes after build and launch my MVC4 web app I got this error.
It can dissapear after rebuild or not.
Same issue I got after publish to Windows Azure.
Does anybody know how to fix this error?
Server Error in '/' Application. Could not load type 'System.Web.Optimization.StyleBundle' from assembly 'System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. 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.TypeLoadException: Could not load type 'System.Web.Optimization.StyleBundle' from assembly 'System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. 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. Stack Trace: [TypeLoadException: Could not load type 'System.Web.Optimization.StyleBundle' from assembly 'System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.] Inventarium.Web.Mobile.App.BundleConfig.RegisterBundles(BundleCollection bundles) in c:devInventariumInventarium.WebInventarium.Web.Mobile.AppApp_StartBundleConfig.cs:30 Inventarium.Web.Mobile.App.MvcApplication.Application_Start() in c:devInventariumInventarium.WebInventarium.Web.Mobile.AppGlobal.asax.cs:18 [HttpException (0x80004005): Could not load type 'System.Web.Optimization.StyleBundle' from assembly 'System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.] System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +4058245 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +191 System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +352 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375 [HttpException (0x80004005): Could not load type 'System.Web.Optimization.StyleBundle' from assembly 'System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11703488 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4870277
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
As per Roman Nikitin Comment:
I found issue myself. There was wrong reference to System.Web.Optimization.dll, my website tried to use old version. Deleting package and then re-adding helps not every time.
The solution is: fully delete old package, references and package configurations from all web-sites and then add it again.
Method 2
We had the same issue on our Windows 2019 Server with IIS 10.10 when trying to access a new application based on .net 5 as a sub application of an existing .net 4.7.x website.
On our web server we run multiple web applications using different .net frameworks
We could solve the exception by applying following steps:
- Download and install the .NET Core Hosting Bundle on the server
- Go to IIS
- Select “Application Pools”
- Add a new Application Pool with following params:
- .NET CLR VERSION: No Managed Code
- Managed Pipeline: Classic
- Assign this new application pool to your new .net 5 web application (under Advanced Settings)
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0