public ActionResult Index()
{
var users = db.Users.Include(u => u.Users1).Include(u => u.User1);
return View(users.ToList());
}
Created an MVC / Entity project in Visual Studio, DB first. Created two controllers, one named Users, the other named Tasks. The page views for Tasks works fine but whenever I try to access the User view pages, I experience this stack overflow.
Application Insights Telemetry (unconfigured): {"name":"Microsoft.ApplicationInsights.Dev.Request","time":"2018-06-03T17:26:09.6757730Z","tags":{"ai.cloud.roleInstance":"DESKTOP-2V3VGT6","ai.operation.id":"lH/a0kZkKsE=","ai.operation.name":"GET Tasks/Index","ai.location.ip":"::1","ai.internal.sdkVersion":"web:2.5.1-195","ai.internal.nodeName":"DESKTOP-2V3VGT6"},"data":{"baseType":"RequestData","baseData":{"ver":2,"id":"|lH/a0kZkKsE=.82dfa1d2_","name":"GET Tasks/Index","duration":"00:00:04.4166410","success":true,"responseCode":"200","url":"http://localhost:62166/Tasks","properties":{"DeveloperMode":"true","_MS.ProcessedByMetricExtractors":"(Name:'Requests', Ver:'1.0')"}}}} An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
The program '[7192] iisexpress.exe' has exited with code -2147023895 (0x800703e9).
Full trace at: https://pastebin.com/raw/846WTUqE
First remove the second include statement and see what the error is after that. If that doesnt work you could try a Select Where expression like this. Add the ToList() to the variable and not the return. Moving the ToList() wont make a different but makes it easier to debug.
public ActionResult Index()
{
var users = db.Users.Select().Where(u => u.Users1).ToList();
return View(users);
}
User contributions licensed under CC BY-SA 3.0