C
C#2y ago
Yashogi

❔ Object reference set to null

var showTime = ShowTimes.Where(x => x.ShowTimeID == request.ShowTimeId).FirstOrDefault();

int totalTicketsRequested = request.RequireTickets.Count();

if (showTime.Theatre.SeatingSize < totalTicketsRequested)
{
throw new Exception("There are not enough seats available for this purchase");
}
var showTime = ShowTimes.Where(x => x.ShowTimeID == request.ShowTimeId).FirstOrDefault();

int totalTicketsRequested = request.RequireTickets.Count();

if (showTime.Theatre.SeatingSize < totalTicketsRequested)
{
throw new Exception("There are not enough seats available for this purchase");
}
With the code shown I am trying to grab the showtimeID the user selected and use it to figure out the seating size of the theatre to ensure the total tickets selected by the user don't exceed the seating size
4 Replies
Yashogi
YashogiOP2y ago
I keep getting object reference set to null and I can't seem to figure out why request is the method placeholder
Thinker
Thinker2y ago
You should be getting a warning that showTime might be null Are you sure there are any items where the ID matches request.ShowTimeId?
FusedQyou
FusedQyou2y ago
The error should give you a stacktrace that point to the exact line the error is thrown at. Could you point out where that is? There's not much context to work with here.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server