Linq contains. ???

Guys, I'm receiving a exception  NULL object with this command.

But my list has 260 object. I just want filter by customer passing some value from a Text component.

Does any one could tell me what's wrong ?

FilteredList = _ManagmentoDTO._Processing._Order._OrderMList.Where(s => s.Customer.StartsWith(txt_filter_Value.Text)).ToList();

Many Thansk
Who is Participating?
BuggyCoderConnect With a Mentor Commented:
Assuming that s.customer returns string, here is a modified version which checks if the customer is not null or empty:-

FilteredList =
.Where(s => (!string.isNullOrEmpty(s.Customer) && s.Customer.StartsWith(txt_filter_Value.Text))).ToList();

This will filter out customer with null or empty data....
MortarelloAuthor Commented:
I tryied StartWith and Constraint get the same erro, and my list has data.
käµfm³d 👽Commented:
If the Customer property (among other potential candidates in that line) hasn't been properly initialized, then you will receive this error.
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

MortarelloAuthor Commented:
Hi kaufmed,

Thanks to try to help me, but the data i can see on Datagrid. i'm just trying to filter then.

In my collection I've got 260 objects with all fields in there. this is very weird.
käµfm³d 👽Connect With a Mentor Commented:
Try clicking in this part of that line:  ...txt_filter_Value.Text...

...then, hit F9 to set a breakpoint. Then run your application. When the lambda is executed, your code will break on that new breakpoint. Then you can step through one-by-one to see which entry raises the exception. Then it becomes a matter of figuring out why whichever member is null.
MortarelloAuthor Commented:
I will double check my list again..
MortarelloAuthor Commented:
Tks guys
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.