I've got a weird problem with some code. If I use this code, it crashes on there custParts.Where(Function(cv), with the error:
Delegate to an instance method cannot have null 'this'
Dim custParts As CustomerPartNumbers = New CustomerPartNumbers()
Dim queryString As String = "Wallpaper"
custParts.Load("DummyCustomer")
If Not custParts Is Nothing Then
Dim qS As String = queryString
Dim cp As CustomerPartNumber
For Each cp In custParts.Where(Function(cv) cv.CustomerPartNumber = qS)
Dim cpPN As String = cp.PartNumber
If prodResults.Where(Function(z) z.PartNumber = cpPN).Count = 0 Then
prodResults.Add(New Hathaway.Library.Part(cpPN))
End If
Next
End If
However, if I put the lambda into a variable, it seems to work without a problem.
Dim custParts As CustomerPartNumbers = New CustomerPartNumbers()
Dim queryString As String = "Wallpaper"
custParts.Load("DummyCustomer")
If Not custParts Is Nothing Then
Dim qS As String = queryString
Dim xxx As Object = custParts.Where(Function(cv) cv.CustomerPartNumber = qS)
Dim cp As CustomerPartNumber
For Each cp In xxx
Dim cpPN As String = cp.PartNumber
Next
End If
Does anybody have any ideas why it's doing this? and why I can't just for Ror Each against my Lambda??
Thanks
Edit:
Bizarrely, this works:
Dim zxcustParts As CustomerPartNumbers = New CustomerPartNumbers()
zxcustParts.Load("DummyCustomer")
Dim zxqueryString As String = "Wallpaper"
For Each zxcustPart In zxcustParts.Where(Function(zxcp) zxcp.CustomerPartNumber = zxqueryString)
Dim cpPN As String = zxcustPart.PartNumber
Next
Edit 2:
Okay, I've actually figured out what this is... My code paste of the failing code actually missed the bit which was causing the error (though I'm sure I just C/P'd straight from the source). So I've updated that.
The problem is trying to do a second ".Where" inside a For Each of the first.