1

I'm trying to create a List of the ApplicationUsers to find the customer that corresponds to the correct Invoice. I tried the following below, but got a NullReferenceException:

System.NullReferenceException: Object reference not set to an instance of an object.

The code in my Controller:

private string FindCustomerForReservation(List<Invoice> invoices, List<ApplicationUser> customers, Reservation currentReservation)
    {
        string customername;

        Invoice correspInvoice = invoices.Find(f => f.Id == currentReservation.Invoicenumber);

        ApplicationUser customer =  customers.Find(k => k.Id == correspInvoice.CustomerId);

        customername = customer.UserName;

        return customername;
    }

So I assume the list is null or empty. Is that correct or is it something else?

How would I fix this?

jwbas
  • 21
  • 1

0 Answers0