Thursday, 16 August 2012

System.Web.HttpException (0x80004005): Failed to load viewstate

Call stack:-

at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
at System.Web.UI.Page.LoadAllState()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

I have had a .NET 1.1 webform operating on a website since 2004 and it should be backward compatible with .NET 4.5 (RTM), and largely, it is! However, I have found that if you use ASP.NET Bundling it will screw up the viewstate and you’ll end up with the error above.  I found this out by decoding the viewstate and noticing it contained data from the Bundling URLs and I thought to myself “Why does bundling care about ViewState?”.  At the moment, I have no solution, however, I’ll post back here if I find one.

You can prove that it’s Bundling that causes the issue by simply removing the call to: System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl from your page

thanks