Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why am I getting an error while running this code?

When I was running a console application, I got this error. This seems to because of a stack overflow error.enter image description here

enter image description here

As this error seems to be in the Assignlogic part of my code, I have wrote down that part of code and the error which is shown. My question is how to handle this exception, without changing the functionality of code?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

//Assign
    public class Assignlogic 
    {
        private List<Assign> Assigns { get; set; } = new List<Assign>();//Here exception unhandled was thrown
//System.StackOverflowException: 'Exception of type 'System.StackOverflowException' was thrown.'

        readonly Assignlogic logicC = new Assignlogic();

        
            

        public void AddEmployeetoProject(Assign assign, Employeelogic logicA, Projectlogic logicB)
        {
            List<Employee> Employes = logicA.Employees;
            List<Project> Projcts = logicB.Projects;
            List<Assign> Assignss = logicC.Assigns;
            var id = assign.EmpId;
            var pid = assign.PID;
            var emp = Employes.Find(a => a.EmpId == id);
            var prjct = Projcts.Find(c => c.PID == pid);
            if (emp != null || prjct != null)
            {
                Assignss.Add(assign);
            }
        }

        //view all assigned projects
        public List<Assign> GetAllAssignedProjects()
        {
            return Assigns;
        }

        //remove an employee from a project
        public void RemoveEmployee(string id)
        {
            var emp = Assigns.Find(a => a.EmpId == id);
            if (emp != null)
            {
                Assigns.Remove(emp);
            }
            
        }

        public bool SearchProjectbyMappedId(string id)
        {
            var employee = Assigns.Find(c => c.EmpId == id);
            if (employee != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }

>Solution :

you have this member in your class AssignLogic

    readonly Assignlogic logicC = new Assignlogic();

So when you create an AssignLogic, it has to go and create an AssignLogic to put there. Creating that AssignLogic requires another AssignLogic,…….

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading