System.InvalidOperationException: Stack empty
Asked Answered
P

13

25

Once running ASP.NET 4.x application built in Visual Studio 2013 I am getting the below exception.

I have tried to disable the PageInspector by removing page inspector assembly

<assemblies>
    <remove assembly="Microsoft.VisualStudio.Web.PageInspector.Loader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</assemblies>

and adding this configuration to app settings

<appSettings>
    <add key="PageInspector:ServerCodeMappingSupport" value="Disabled"/>
</appSettings>

Nothing helped.

[/Pages/TargetPage.aspx] System.Web.HttpException (0x80004005): Exception of type 'System.Web.HttpException' was thrown. ---> System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: Stack empty.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.Stack`1.Pop()
   at Microsoft.VisualStudio.Web.PageInspector.Runtime.WebForms.SelectionMappingRenderTraceListener.EndRendering(TextWriter writer, Object renderedObject)
   at System.Web.UI.RenderTraceListener.RenderTraceListenerList.EndRendering(TextWriter writer, Object renderedObject)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.LegacyPageAsyncInfo.<CallHandlersPossiblyUnderLock>b__32(Object o)
   at System.Web.HttpContext.InvokeCancellableCallback(WaitCallback callback, Object state)
   at System.Web.UI.Page.LegacyPageAsyncInfo.CallHandlersPossiblyUnderLock(Boolean onPageThread)
   at System.Web.UI.Page.LegacyPageAsyncInfo.CallHandlers(Boolean onPageThread)
   at System.Web.HttpAsyncResult.End()
   at System.Web.UI.Page.LegacyAsyncPageEndProcessRequest(IAsyncResult result)
   at System.Web.UI.Page.AsyncPageEndProcessRequest(IAsyncResult result)

Is there any way how to avoid the exception? Thanks a lot for any suggestions

Persistent answered 5/12, 2013 at 17:20 Comment(0)
M
9

There are multiple reasons why the

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. -
System.InvalidOperationException: Stack empty.
Microsoft.VisualStudio.Web.PageInspector.Runtime.WebForms.SelectionMappingRenderTraceListener.EndRendering(TextWriter writer, Object renderedObject)
...

After adding as proposed:

 <appSettings>
   <add key="PageInspector:ServerCodeMappingSupport" value="Disabled"/>
   ...
 </appSettings>

I noticed I had duplicate selected item on a dropdown list creating the issue.

Maynor answered 31/7, 2015 at 13:8 Comment(0)
E
26

I disabled browser link in VS 2013 and was able to see the actual cause of the error. It is usually something underlying when browser link is set. You can see how to disable it here: http://www.poconosystems.com/software-development/how-to-disable-browser-link-in-visual-studio-2013/

Entryway answered 24/10, 2014 at 9:48 Comment(2)
Also helpful in VS 2017Praetorian
This is a dead link. Here is one that works: #23101765Caroylncarp
S
26

This can happen if the AssociatedControlID on a label is associated with a control which can't be found.

Shutdown answered 25/4, 2016 at 11:14 Comment(0)
M
9

There are multiple reasons why the

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. -
System.InvalidOperationException: Stack empty.
Microsoft.VisualStudio.Web.PageInspector.Runtime.WebForms.SelectionMappingRenderTraceListener.EndRendering(TextWriter writer, Object renderedObject)
...

After adding as proposed:

 <appSettings>
   <add key="PageInspector:ServerCodeMappingSupport" value="Disabled"/>
   ...
 </appSettings>

I noticed I had duplicate selected item on a dropdown list creating the issue.

Maynor answered 31/7, 2015 at 13:8 Comment(0)
B
8

Hope this help somebody.

I was getting this error when my asp:panel has a default button say XYZ and I modified the name XYZ and forgot to change default button name in panel.

Berhley answered 19/12, 2015 at 14:53 Comment(0)
P
4

I have found the problem. There was changed way how to generate IDs of controls in GridView from default to

ClientIDMode="Predictable" ClientIDRowSuffix="ID"

Which resulted in the exception. Not sure why the real exception was hidden by PageInspector stack empty. Just reverting the change to original resolved the issue.

Now the exception is different (but once GridView settings is back to original this disapper too)

System.ArgumentException: An entry with the same key already exists.
Persistent answered 6/12, 2013 at 9:25 Comment(2)
Thanks, adding <add key="PageInspector:ServerCodeMappingSupport" value="Disabled"/> solved the problem for me!Megadeath
@mybrave: Can you please write an answer for the "PageInspector:ServerCodeMappingSupport" key, as this seems to be the solution for quite a few people (for me as well).Triaxial
M
3

I've also seen this problem in some web apps running on dev machines using Visual Studio 2013 with "Browser Link" enabled.

In multiple cases that I have seen, leaving Browser Link enabled causes all sorts of issues, both client script and security warnings, and server exceptions like this one (annoying thing is that it appears to be enabled by default, thanks Msft!)

Millicentmillie answered 7/10, 2014 at 21:43 Comment(0)
N
2

I had the same exception, but in my case the problem was the following was missing:

<form runat="server">
</form>
Nowt answered 31/7, 2014 at 1:31 Comment(0)
T
2

In my case (ASP.NET 4.6, Visual Studio 2015) I commented an asp text control and added a new asp drop down list but did not updated the AssociatedControlID of the associated label.

on changing the AssociatedControlID to newly added asp drop down list ID my problem was fixed.

Timothee answered 26/5, 2016 at 17:7 Comment(0)
M
1

That Happend to me when I added a new <asp:Panel> to my page and set the DefaultButton to a button outside the panel (By mistake). Error fixed when I changed the DefaultButton to another one inside the panel.

Monotone answered 17/2, 2017 at 12:4 Comment(0)
S
1

In my case, I have removed an asp:DropDownList, and there was a asp:Label associated to its ID with AssociatedControlID. After removing the associated control Id, it worked.

Schoolbag answered 22/6, 2023 at 16:26 Comment(0)
A
0

We started VisualStudio 2015 (vs2015) from VisualStudio 2012 solution file and while building all the projects didnot build. This was due to the Enable Browser Link option enabled by default. I disabled the Enable Browser Link option and Re-built the solution which built all the projects successfully. After this I fired up the url in a browser and Boom it worked! For those who have similar scenario like mine. give it a whirl !

April answered 22/11, 2016 at 15:55 Comment(0)
D
0

In my case, because I had so many issues migrating a website from VS2002 to VS2015, I decided to create a new project on VS2015 and transfer all webforms from the old project (VS2002) to the new one (VS2015).

The new project had a Site.Master page, which already has a tag. Because I was transferring old webforms without modification, they already had a tag too, so each page trying to load had two tags inside.

When I removed the tag on each page, leaving only the one on Site.Master page, the problem was solved.

I hope this helps.

Dissatisfied answered 25/8, 2017 at 20:20 Comment(0)
L
0

I face this problem while selecting different dropdown value and below is the solution of the problem

First clear the selected value for dropdown and then enable other dropdown value selection

dropdown.ClearSelection();
dropdown.Items.FindByValue(result.Birthday.Value.Year.ToString()).).Selected = true;
Lumpy answered 6/4, 2021 at 8:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.