Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
1.10/5 (3 votes)
See more:
i am doing MVC Application.i Created Model Clss(DinnerRepository.cs, Dinner.cs), Also created Controller Clsaa (DinnerController.cs).And i created two views Not Found.aspx, Details.aspx. while running the Application I am facing this error "An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll". plz hlp me
Posted

Somewhere in your code, it's become stuck in something like a recursive loop and it will run and run until there is no more stack space available. Poorly named properties can also cause this...
e.g.

C#
private int _myProperty;
public int MyProperty
{
    get {return _myProperty;}
    set {MyProperty = value;} // Oops, this will cause Stack overflow...should've been '_myProperty = value'
}



From what you've posted, it's impossible to say whereabouts this is happening, you need to debug it yourself. Determine where abouts in the application the exception is occurring and put a breakpoint on the controller action you think may be the cause. Step through the code, you should see where a function is being called over and over.
 
Share this answer
 
v2
StackOverflowException usually means you've ended up in an infinite recursive loop. If I were in your shoes I'd be looking for where it'd be possible for one of your methods or properties to call itself (or call another method chain which loops back to itself).
 
Share this answer
 
This type of exception is actually the easiest to discover under debugger. You should just run the code until exception is caught by the debugger and look at the call stack. (With Visual Studio, you can show the debug windows "Call Stack".) Find at least one method called several times, put a breakpoint on its first statement. Every time your execution stops at the break point, look at the stack. You mean need to shift a break point or add some new ones to get closer to the source of the problem.

You need to find out why recursive never ends and develop a condition of the exit from recursion.

Actually, it's much harder to explain than actually achieve. The process of the debugging always converges, and usually it happens very quickly, if you understand how your code basically works.

—SA
 
Share this answer
 
Comments
Thin July 4-May-12 6:44am    
If you instantiate in constructor Class
It will make infinite looping

eg:
Sergey Alexandrovich Kryukov 8-May-12 13:12pm    
This is very usual mistake. Perhaps you need to elaborate your answer. What you say is not directly related to mine, where I describe the general method of finding such bugs.
--SA
XML
namespace Tenant.DataAccess
{
    public class TenantOrderDAO : GenericCommon<OrderInfo>
    {
        private OrderInfo mOrderInfo;
        public TenantOrderDAO mTO_DAO { get; set; }

        public OrderInfo OrderInfo
        {
            get { return mOrderInfo; }
            set { mOrderInfo = value; }
        }

        public TenantOrderDAO()
        {
            mOrderInfo = new OrderInfo();
            mTO_DAO = new TenantOrderDAO();
        }

}
 
Share this answer
 
Comments
Sandeep Mewara 4-May-12 9:30am    
Elaborate please!
Member 13765552 2-Jul-18 10:32am    
In my app, i use GMap.NET.WindowsForms version 1.8.5.0;
when I drap thi control to form, it generate code: this.gmap = new GMap.NET.WindowsForms.GMapControl();

It build susscesstfull, but when run this app, it's have an error:

An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

i don't know why. can any one help me sold this error.

Thanks,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900