0

Hey I'm working on a school project and when I set the variable of a class it throws me a NullReferenceException You can find the full project @ https://github.com/kyllianlissens/BugManagment

if (!dataReader.IsDBNull(dataReader.GetOrdinal("user_id")))
{
    task.Employee = (Employee) UserRepository.Items.Find(x => x.Id.Equals(Convert.ToInt32(dataReader["user_id"])));
}

it happens on settings the task.Employee variable

and this is My task class

public class Task : Entity
{
    internal Task(int id, Bug bug, string description, int size, TimeSpan timeSpent) : base(id)
    {
        Bug = bug;
        Size = size;
        TimeSpent = timeSpent;
        Description = description;
        Employee = null;
    }

    public Employee Employee { get; internal set; }
    public Bug Bug { get; internal set; }
    public string Description { get; internal set; }
    public int Size { get; internal set; }
    public TimeSpan TimeSpent { get; internal set; }

    internal void AddTime(TimeSpan time)
    {
        TimeSpent += time;
    }
}

I also tried removing the Employee = null; but that doesn't change anything.

Filburt
  • 17,626
  • 12
  • 64
  • 115
RefDev001
  • 13
  • 4
  • 3
    You need to learn how to debug, break point, and inspect code using the various debugging tools. You will then find your null reference, and inturn have an understanding of what you might do to fix it – TheGeneral Mar 02 '20 at 21:17
  • 1
    Just because you don't explicitly set an object `null`, doesn't mean is isn't :) – Broots Waymb Mar 02 '20 at 21:20
  • If you can post whole exception (message + stack trace), we can help better. – Alex - Tin Le Mar 02 '20 at 21:26

0 Answers0