Anytime I use combinedResultList in a query I get a null reference exception when I try to initialize it. If I don't use it in the query below it, it works fine. Is there something wrong with my query that is causing the null reference? I am just trying to get back any rows that have a coupon id contained within the combinedResultList
var combinedResultList = visionLines.Where(line => line != null).SelectMany(line => line.VisionResults).Distinct().ToList(); //Get Null reference exception here
eventsFromDb = (from e in db.Events //If I comment out this query the above statement works and no longer throws the null reference exception
where (combinedResultList.Select(result => result.CouponId)).Contains(e.CouponIdentifier)
&& e.ExpiryDate >= _minExpiryDate
select new EventDataTransferObject { EventIdentifier = e.EventIdentifier, DateLastUpdated = e.DateLastUpdated }).ToList();
Error Message:
Object reference not set to an instance of an object.
Stack Trace:
at MyProject.UI.ViewModel.SelectionEditorViewModel.GetEventsByCouponName(String couponName, CancellationToken ct) in C:\MyProject.UI\ViewModel\SelectionEditorViewModel.cs:line 845