I have a small ASP.NET MVC5 project using Entity Framework Code First. I have placed a breakpoint in my controller so that I can examine the contents of my variables to ensure that they all contain what they should contain. One such variable is a complex model object which I query from the context and when I try to expand that object to view its properties, the debugger simply closes with no obvious error message. The only explanation that I get is in the Output which reads:
The program '[10820] iisexpress.exe: Program Trace' has exited with code 0 (0x0). The program '[10820] iisexpress.exe' has exited with code -2147023895 (0x800703e9). The program '[12128] iexplore.exe' has exited with code -1 (0xffffffff).
I looked up exit code -2147023895 (0x800703e9) and only got that it is a stack overflow issue which really doesn't help to figure out what is causing it.
The most unusual thing is that if I let the application run, it loads the page with no problem and doesn't seem to throw any errors at all. What's going on here?
Here's my relevant code:
Controller
public ActionResult Index()
{
//This is the line that crashed the debugger if I try to expand quarter
//after it is filled. There will only ever by one item marked isCurrent.
Quarter quarter = db.Quarter.First(x => x.isCurrent == true);
...
}
Model
public class Quarter
{
public int Id {get; set;}
public Enums.QuarterEnum Quarter {get; set;}
public string Year {get; set;}
public bool isCurrent {get; set;}
[NotMapped]
public string QuarterAndYear {get{ return QuarterAndYear; }}
}
View
...
@Html.LabelFor(model => model.Quarter.Quarter)
@Html.DisplayFor(model => model.Quarter.Quarter)
...
I searched around for a solution to this problem but could not find anything that really helped me so I opted to post this here with an explanation of why this occurred and the super easy change that fixed it.
The problem was in the model with the line:
public string QuarterAndYear {get{ return QuarterAndYear; }}
A careless mistake on my part by telling it to return itself which caused me a huge headache in trying to figure out why it was crashing with no error message. It should have been:
public string QuarterAndYear {get{ return Quarter.toString() + " Quarter of " + Year;}}
Because I was not actually referencing the QuarterAndYear in the view, no errors were thrown when I loaded the page and it seemed to run perfectly. However, when I tried to view the properties of the Quarter object while debugging, it was trying to resolve QuarterAndYear (which was returning itself) and was crashing the debugger.
User contributions licensed under CC BY-SA 3.0