Out of nowhere, earlier this week, I started running into a StackOverflowException
in our ASP.NET MVC application. We've been developing this application for 2 years. I'm the only developer (of 3 developers) who is seeing this problem. I've been struggling to get a good stack trace and I finally got one and it turns out that it's happening completely outside of our code. The exception is in the JsMinify.Process()
and Microsoft.Ajax.Utilities
areas of the code. I'm completely stumped. We weren't even aware that any minification was taking place. I've never noticed any of our scripts being minified when debugging in the browser. But that's neither here nor there. I'm stumped. I have no clue how to fix this. I'm hoping some of the brilliant folks here can give me a hand.
The StackOverFlowException
doesn't happen every time, but it might happen 20 times in a row and then the app may work fine for a while and then it starts happening again. It's brought my productivity to a screeching halt. I don't debug from VS.NET. I deploy to a regular IIS Server and then I manually go to the site in the browser. When I do, I get the StackOverflowException
before anything really comes up. We have an Application_Start()
and Application_AuthenticateRequest()
in our Global.asax.cs
and these get called. We also have a Application_End()
which does not get called if the StackOverflowException
happens.
My stack is below (taken from WinDbg). I've cut it off (as, obviously, it's huge), but you can see, it's the chain of 3 methods that are getting called recursively until it dies. I'm perfectly satisfied with disabling minification if that's a possibility, but I'd rather solve it properly if I can:
0465db94 079d6e3b Microsoft.Ajax.Utilities.OutputVisitor.AcceptNodeWithParens(Microsoft.Ajax.Utilities.AstNode, Boolean)
0465dbac 079d6c6e Microsoft.Ajax.Utilities.OutputVisitor.Visit(Microsoft.Ajax.Utilities.BinaryOperator)
0465dbd0 09e3973b Microsoft.Ajax.Utilities.BinaryOperator.Accept(Microsoft.Ajax.Utilities.IVisitor)
0465dbd8 079d6e3b Microsoft.Ajax.Utilities.OutputVisitor.AcceptNodeWithParens(Microsoft.Ajax.Utilities.AstNode, Boolean)
0465dbf0 079d6c6e Microsoft.Ajax.Utilities.OutputVisitor.Visit(Microsoft.Ajax.Utilities.BinaryOperator)
0465dc14 09e3973b Microsoft.Ajax.Utilities.BinaryOperator.Accept(Microsoft.Ajax.Utilities.IVisitor)
0465dc1c 079d6e3b Microsoft.Ajax.Utilities.OutputVisitor.AcceptNodeWithParens(Microsoft.Ajax.Utilities.AstNode, Boolean)
0465dc34 079d6c6e Microsoft.Ajax.Utilities.OutputVisitor.Visit(Microsoft.Ajax.Utilities.BinaryOperator)
0465dc58 09e3973b Microsoft.Ajax.Utilities.BinaryOperator.Accept(Microsoft.Ajax.Utilities.IVisitor)
0465dc60 079d6e3b Microsoft.Ajax.Utilities.OutputVisitor.AcceptNodeWithParens(Microsoft.Ajax.Utilities.AstNode, Boolean)
0465dc78 079d6c6e Microsoft.Ajax.Utilities.OutputVisitor.Visit(Microsoft.Ajax.Utilities.BinaryOperator)
0465dc9c 09e3973b Microsoft.Ajax.Utilities.BinaryOperator.Accept(Microsoft.Ajax.Utilities.IVisitor)
0465dca4 079d6e3b Microsoft.Ajax.Utilities.OutputVisitor.AcceptNodeWithParens(Microsoft.Ajax.Utilities.AstNode, Boolean)
0465dcbc 079d6c6e Microsoft.Ajax.Utilities.OutputVisitor.Visit(Microsoft.Ajax.Utilities.BinaryOperator)
0465dce0 09e3973b Microsoft.Ajax.Utilities.BinaryOperator.Accept(Microsoft.Ajax.Utilities.IVisitor)
0465dce8 079d6e3b Microsoft.Ajax.Utilities.OutputVisitor.AcceptNodeWithParens(Microsoft.Ajax.Utilities.AstNode, Boolean)
0465dd00 079d6c6e Microsoft.Ajax.Utilities.OutputVisitor.Visit(Microsoft.Ajax.Utilities.BinaryOperator)
0465dd24 09e3973b Microsoft.Ajax.Utilities.BinaryOperator.Accept(Microsoft.Ajax.Utilities.IVisitor)
0465dd2c 079d6e3b Microsoft.Ajax.Utilities.OutputVisitor.AcceptNodeWithParens(Microsoft.Ajax.Utilities.AstNode, Boolean)
0465dd44 079d6c6e Microsoft.Ajax.Utilities.OutputVisitor.Visit(Microsoft.Ajax.Utilities.BinaryOperator)
0465dd68 09e3973b Microsoft.Ajax.Utilities.BinaryOperator.Accept(Microsoft.Ajax.Utilities.IVisitor)
0465dd70 079d6e3b Microsoft.Ajax.Utilities.OutputVisitor.AcceptNodeWithParens(Microsoft.Ajax.Utilities.AstNode, Boolean)
0465dd88 079d6c6e Microsoft.Ajax.Utilities.OutputVisitor.Visit(Microsoft.Ajax.Utilities.BinaryOperator)
0465ddac 09e3973b Microsoft.Ajax.Utilities.BinaryOperator.Accept(Microsoft.Ajax.Utilities.IVisitor)
0465ddb4 079d69e7 Microsoft.Ajax.Utilities.OutputVisitor.Visit(Microsoft.Ajax.Utilities.Block)
0465ddd0 09e393eb Microsoft.Ajax.Utilities.Block.Accept(Microsoft.Ajax.Utilities.IVisitor)
0465ddd8 079d7ab5 Microsoft.Ajax.Utilities.OutputVisitor.OutputFunctionArgsAndBody(Microsoft.Ajax.Utilities.FunctionObject, Boolean)
0465ddf4 079d7911 Microsoft.Ajax.Utilities.OutputVisitor.Visit(Microsoft.Ajax.Utilities.FunctionObject)
0465de0c 09e399eb Microsoft.Ajax.Utilities.FunctionObject.Accept(Microsoft.Ajax.Utilities.IVisitor)
0465de14 079d6e3b Microsoft.Ajax.Utilities.OutputVisitor.AcceptNodeWithParens(Microsoft.Ajax.Utilities.AstNode, Boolean)
0465de2c 079d7718 Microsoft.Ajax.Utilities.OutputVisitor.Visit(Microsoft.Ajax.Utilities.CallNode)
0465de54 09e3991b Microsoft.Ajax.Utilities.CallNode.Accept(Microsoft.Ajax.Utilities.IVisitor)
0465de5c 079d6e3b Microsoft.Ajax.Utilities.OutputVisitor.AcceptNodeWithParens(Microsoft.Ajax.Utilities.AstNode, Boolean)
0465de74 079d6b5f Microsoft.Ajax.Utilities.OutputVisitor.Visit(Microsoft.Ajax.Utilities.BinaryOperator)
0465de98 09e3973b Microsoft.Ajax.Utilities.BinaryOperator.Accept(Microsoft.Ajax.Utilities.IVisitor)
0465dea0 079d6e3b Microsoft.Ajax.Utilities.OutputVisitor.AcceptNodeWithParens(Microsoft.Ajax.Utilities.AstNode, Boolean)
0465deb8 079d6c6e Microsoft.Ajax.Utilities.OutputVisitor.Visit(Microsoft.Ajax.Utilities.BinaryOperator)
0465dedc 09e3973b Microsoft.Ajax.Utilities.BinaryOperator.Accept(Microsoft.Ajax.Utilities.IVisitor)
0465dee4 079d69e7 Microsoft.Ajax.Utilities.OutputVisitor.Visit(Microsoft.Ajax.Utilities.Block)
0465df00 09e393eb Microsoft.Ajax.Utilities.Block.Accept(Microsoft.Ajax.Utilities.IVisitor)
0465df08 079d682d Microsoft.Ajax.Utilities.AstNode.ToCode()
0465df3c 0a51a2fe Microsoft.Ajax.Utilities.Minifier.MinifyJavaScript(System.String, Microsoft.Ajax.Utilities.CodeSettings)
0465df70 0a51a02d System.Web.Optimization.JsMinify.Process(System.Web.Optimization.BundleContext, System.Web.Optimization.BundleResponse)
0465df8c 0a519f56 System.Web.Optimization.Bundle.ApplyTransforms(System.Web.Optimization.BundleContext, System.String, System.Collections.Generic.IEnumerable`1<System.IO.FileInfo>)
0465dfc4 0a518afd System.Web.Optimization.Bundle.GenerateBundleResponse(System.Web.Optimization.BundleContext)
0465dfd8 0a518929 System.Web.Optimization.Bundle.GetBundleResponse(System.Web.Optimization.BundleContext)
0465dfec 0a5186b7 System.Web.Optimization.BundleResolver.GetBundleContents(System.String)
0465e02c 0a5183cb System.Web.Optimization.AssetManager.DeterminePathsToRender(System.Collections.Generic.IEnumerable`1<System.String>)
0465e060 0a5181df System.Web.Optimization.AssetManager.RenderScripts(System.Collections.Generic.IEnumerable`1<System.String>)
0465e0ac 0a51815f System.Web.Optimization.AssetManager.RenderExplicit(Boolean, System.String[])
0465e0c4 0a517fb9 System.Web.Optimization.Scripts.Render(System.String[])
0465e0d0 0a511e93 ASP._Page_Views_Shared__Layout_cshtml.Execute()
0465e594 058058f6 *** WARNING: Unable to verify checksum for System.Web.WebPages.ni.dll
*** ERROR: Module load completed but symbols could not be loaded for System.Web.WebPages.ni.dll
System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
0465e5b8 5f1b2af2 *** WARNING: Unable to verify checksum for System.Web.Mvc.ni.dll
*** ERROR: Module load completed but symbols could not be loaded for System.Web.Mvc.ni.dll
System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
0465e5d4 05805991 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(System.Web.WebPages.WebPageContext, System.IO.TextWriter, System.Web.WebPages.WebPageRenderingBase)
0465e5f0 05806f7a System.Web.WebPages.WebPageBase+<>c__DisplayClass7.<RenderPageCore>b__6(System.IO.TextWriter)
0465e618 057f3d8b System.Web.WebPages.HelperResult.WriteTo(System.IO.TextWriter)
0465e61c 05804d24 System.Web.WebPages.WebPageBase.Write(System.Web.WebPages.HelperResult)
0465e630 05804ef9 System.Web.WebPages.WebPageBase.RenderSurrounding(System.String, System.Action`1<System.IO.TextWriter>)
0465e648 05805717 System.Web.WebPages.WebPageBase.PopContext()
0465e668 05805998 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(System.Web.WebPages.WebPageContext, System.IO.TextWriter, System.Web.WebPages.WebPageRenderingBase)
0465e684 5f1af8f5 System.Web.Mvc.RazorView.RenderView(System.Web.Mvc.ViewContext, System.IO.TextWriter, System.Object)
0465e6ac 5f199b34 System.Web.Mvc.BuildManagerCompiledView.Render(System.Web.Mvc.ViewContext, System.IO.TextWriter)
0465e6cc 5f1d6f98 System.Web.Mvc.ViewResultBase.ExecuteResult(System.Web.Mvc.ControllerContext)
0465e6f0 5f1b747e System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(System.Web.Mvc.ControllerContext, System.Web.Mvc.ActionResult)
0465e6fc 5f1b8058 System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17()
0465e70c 5f1b6bfc System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(System.Web.Mvc.IResultFilter, System.Web.Mvc.ResultExecutingContext, System.Func`1<System.Web.Mvc.ResultExecutedContext>)
0465e740 5f1b9006 System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1a+<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
0465e748 5f1b6bfc System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(System.Web.Mvc.IResultFilter, System.Web.Mvc.ResultExecutingContext, System.Func`1<System.Web.Mvc.ResultExecutedContext>)
0465e77c 5f1b9006 System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1a+<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
0465e784 5f1b6d5e System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(System.Web.Mvc.ControllerContext, System.Collections.Generic.IList`1<System.Web.Mvc.IResultFilter>, System.Web.Mvc.ActionResult)
0465e7a0 5f1bb94a System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass25+<>c__DisplayClass2a.<BeginInvokeAction>b__20()
0465e7b4 5f1ba895 System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass25.<BeginInvokeAction>b__22(System.IAsyncResult)
0465e7e0 5f1bacb6 System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResult`1[[System.Boolean, mscorlib]].End()
0465e7ec 5f1b9d8c System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(System.IAsyncResult)
0465e7f8 5f1bf2bf System.Web.Mvc.Controller+<>c__DisplayClass1d.<BeginExecuteCore>b__18(System.IAsyncResult)
0465e804 5f1bbb58 System.Web.Mvc.Async.AsyncResultWrapper+<>c__DisplayClass4.<MakeVoidDelegate>b__3(System.IAsyncResult)
0465e814 5f1bbf57 System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResult`1[[System.Web.Mvc.Async.AsyncVoid, System.Web.Mvc]].End()
0465e824 5f1bd1b2 System.Web.Mvc.Controller.EndExecuteCore(System.IAsyncResult)
0465e84c 5f1bbb58 System.Web.Mvc.Async.AsyncResultWrapper+<>c__DisplayClass4.<MakeVoidDelegate>b__3(System.IAsyncResult)
0465e85c 5f1bbf57 System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResult`1[[System.Web.Mvc.Async.AsyncVoid, System.Web.Mvc]].End()
0465e86c 5f1bd21c System.Web.Mvc.Controller.EndExecute(System.IAsyncResult)
0465e87c 5f1bd51b System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(System.IAsyncResult)
0465e884 5f1c3346 System.Web.Mvc.MvcHandler+<>c__DisplayClass8.<BeginProcessRequest>b__3(System.IAsyncResult)
0465e8a4 5f1bbb58 System.Web.Mvc.Async.AsyncResultWrapper+<>c__DisplayClass4.<MakeVoidDelegate>b__3(System.IAsyncResult)
0465e8b4 5f1bbf57 System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResult`1[[System.Web.Mvc.Async.AsyncVoid, System.Web.Mvc]].End()
0465e8c4 5f1c2d08 System.Web.Mvc.MvcHandler.EndProcessRequest(System.IAsyncResult)
0465e8d4 5f1c2eaa System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(System.IAsyncResult)
0465e8dc 6ac4f3e9 *** WARNING: Unable to verify checksum for System.Web.ni.dll
System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
0465e920 6a2f49dc System.Web.HttpApplication.ExecuteStep(IExecutionStep, Boolean ByRef)
0465e964 6a3078d7 System.Web.HttpApplication+PipelineStepManager.ResumeSteps(System.Exception)
0465ea44 6a2f4c40 System.Web.HttpApplication.BeginProcessRequestNotification(System.Web.HttpContext, System.AsyncCallback)
0465ea5c 6a2f140b System.Web.HttpRuntime.ProcessRequestNotificationPrivate(System.Web.Hosting.IIS7WorkerRequest, System.Web.HttpContext)
0465eaac 6a2f6d27 System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr, IntPtr, IntPtr, Int32)
0465eab0 6a2f6a1f [InlinedCallFrame: 0465eab0]
0465eba8 6a2f6a1f System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr, IntPtr, IntPtr, Int32)
0465f074 00bfa842 [InlinedCallFrame: 0465f074]
0465f070 6a35b10d DomainNeutralILStubClass.IL_STUB_PInvoke(IntPtr, System.Web.RequestNotificationStatus ByRef)
0465f074 6a2f6ea6 [InlinedCallFrame: 0465f074] System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr, System.Web.RequestNotificationStatus ByRef)
0465f0a8 6a2f6ea6 System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr, IntPtr, IntPtr, Int32)
0465f0ac 6a2f6a1f [InlinedCallFrame: 0465f0ac]
0465f1a4 6a2f6a1f System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr, IntPtr, IntPtr, Int32)
0465f27c 00bfa842 [ContextTransitionFrame: 0465f27c]
Update: I have a temporary solution, which I got from the answer to this question: How to disable Javascript/CSS minification in ASP.NET MVC 4 Beta
The solution is to disable the minification. That avoids the StackOverflowException
, but I'd like to fix the actual cause of the StackOverflowException
so we can at least benefit from what minification does take place. I now see why not all of our stuff is minified, which is nice to know.