This is the extract of a linq expression:
Dim charges As List(Of IndividualCharge) = (From t In totals
Group t By t.InvId
Into Group
Select New IndividualCharge With {
.VatRate = Group.FirstOrDefault(Function(x) x.VatRate).VatRate
}).ToList()
It appears that when x.VatRate
is 0
, FirstOrDefault
throws an exception:
I can confirm this by swapping it out for:
.VatRate = Group.FirstOrDefault(Function(x) 0).VatRate
which ensures an exception every time.
- Why is a null reference exception thrown (this is a value type, hence no references)?
- How do I deal with the situation where x.VatRate is actually
0
?