locked
StackOverflowException when including a navigation property RRS feed

  • Question

  • User-2022472003 posted

    I have a collection of ProjectMissingPeople as a navigation property on Project. When I try to include them when passing a list of Project to a view, I get a stack overflow exception. Do you know how to fix it?

    Code that is generating error:

    public ActionResult Index()
    {
       return View(db.Projects.Include(p => p.ProjectMissingPeople).ToList());
    }

    Project class:

    public class Project
    {
        public int ProjectID { get; set; }
        ...
        public virtual ICollection<ProjectMissingPeople> ProjectMissingPeople { get; set; }
    
    }

    ProjectMissingPeople class:

    public class ProjectMissingPeople
    {
        public int ProjectMissingPeopleID { get; set; }
        public string Text { get; set; }
        public bool Open { get; set; }
        public int ProjectID { get; set; }
        public virtual Project Project { get; set; }
    
    }
    Tuesday, October 3, 2017 7:57 PM

All replies

  • User-335504541 posted

    Hi pontushejsan,

    Usually stack overflow means the stack is "full" for example when calling a procedure directly or indirectly from itself resulting in "infinite" nested calls filling up the whole stack.

    Do you have other  codes in the controller? I have tested your provide code. It works at my place.

    Best Regards,

    Billy

    Wednesday, October 4, 2017 7:30 AM