Scenario:
Getting the LINQ error "Object reference not set to an instance of an object." while using 'Contains' for filtering data in the source code below:
var filteredlist = lstXXX.Where(c => c.<Property Name>.Contains(search string));
Solution:
filteredlist = lstXXX.Where(c =>c.<Property Name>!= null && c.<Property Name>.Contains(search string));
Getting the LINQ error "Object reference not set to an instance of an object." while using 'Contains' for filtering data in the source code below:
Solution:
It is required to include the Not NULL condition/s or Hasvalue==true for the properties considered in the Where clause as shown in below statement.
Otherwise the LINQ error "Object reference not set to an instance of an object." gets raised in the application.
var