0

I have this return Statement,

return taskItems.Where(s => s.DateCreated >= fromDate.SelectedDate || s.DateCreated <= toDate.SelectedDate);

This should work, but Visual Studio is giving me this exception on the "InitializeComponent();",

 Object reference not set to an instance of an object.

This is what's used to load the tasks into the Datagrid being used,

private IEnumerable<TaskEntry> LoadTasks()
    {
        var data = GetListItems("Tasks");
        var result = XElement.Parse(data.OuterXml);
        XNamespace z = "#RowsetSchema";
        var taskItems = from r in result.Descendants(z + "row")



                        //where r.Attribute("ows_Created") 
                        //where r.Attribute("ows_Client_x0020_Issue") == null

                        select new TaskEntry 
                        {
                            ID = r.Attribute("ows_ID") != null ? r.Attribute("ows_ID").Value : string.Empty,
                            IssueID = r.Attribute("ows_Client_x0020_Issue") != null ? r.Attribute("ows_Client_x0020_Issue").Value : string.Empty,
                            Client = r.Attribute("ows_Client") != null ? r.Attribute("ows_Client").Value : string.Empty,
                            Title = r.Attribute("ows_Title") != null ? r.Attribute("ows_Title").Value : string.Empty,
                            TaskType = r.Attribute("ows_Task_x0020_Type") != null ? r.Attribute("ows_Task_x0020_Type").Value : string.Empty,
                            Priority = r.Attribute("ows_Priority") != null ? r.Attribute("ows_Priority").Value : string.Empty,
                            Status = r.Attribute("ows_Status") != null ? r.Attribute("ows_Status").Value : string.Empty,
                            AssignedTo = r.Attribute("ows_AssignedTo") != null ? r.Attribute("ows_AssignedTo").Value : string.Empty,
                            Owner = r.Attribute("ows_Owner") != null ? r.Attribute("ows_Owner").Value : string.Empty,
                            Body = r.Attribute("ows_Body") != null ? r.Attribute("ows_Body").Value : string.Empty,
                            DueDate = Convert.ToDateTime(r.Attribute("ows_DueDate").Value).Date,
                            DateCreated = Convert.ToDateTime(r.Attribute("ows_Created").Value).Date,
                            Area = r.Attribute("ows_Area") != null ? r.Attribute("ows_Area").Value : string.Empty,
                            GroupTask = r.Attribute("ows_Group_x0020_Task") != null ? r.Attribute("ows_Group_x0020_Task").Value : string.Empty,
                        };

        return taskItems.Where(s => s != null && (s.DateCreated >= fromDate.SelectedDate || s.DateCreated <= toDate.SelectedDate));
    }
Sandro Perez
  • 120
  • 1
  • 11

1 Answers1

0

You need to check that that values you are using for date filters are actually set. It would seem either fromDate or toDate are null or though without seeing some more code it is hard to say?

Luthervd
  • 1,388
  • 2
  • 14
  • 25