-2

i am getting Getting Object reference not set to an instance of an object error
my code and the image are attached below

   public class Backlogitem
        {
            public string Name { get; set; }
            public int ID { get; set; }

            public string State { get; set; }
           // public DateTime? due { get; set; }
            public int priorty { get; set; }
            public int Size { get; set; }
          //  public int effort { get; set; }
            public int StoryPoints { get; set; }
            public string DoneStatus { get; set; }
            public string StoryOwner { get; set; }
            public string Assignedto { get; set; }
            public string StoryAuthor { get; set; }
            public string IterationPath { get; set; }

        }

enter image description here values of the property

workitemlist image
enter image description here rest of the code is pasted here
https://github.com/akhiljain1611/TFS/blob/master/README.md

Akhil Jain
  • 500
  • 1
  • 3
  • 19

1 Answers1

3

You need to initialize the lists (Issues, Tasks and PBacklog) before you can begin adding items to it. I have done it using a constructor:

public class WorkItemViewModel
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string AssignedTo { get; set; }
    public string WorkitemType { get; set; }
    public string Priorty { get; set; }
    public string IterationPath { get; set; }
    public string State { get; set; }
    public List<TFSIssue> Issues { get; set; }
    public List<TFSTask> Tasks { get; set; }
    public List<Backlogitem> PBacklog { get; set;}

    public WorkItemViewModel()  // Added a public constructor
    {
        Issues = new List<TFSIssue>();
        Tasks = new List<TFSTask>();
        PBacklog =  new List<Backlogitem>();
    }
}
FaizanHussainRabbani
  • 2,826
  • 2
  • 19
  • 41