Saturday, February 16, 2013

LINQ error "Object reference not set to an instance of an object." while using 'Contains' for filtering data

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:

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 filteredlist = lstXXX.Where(c =>c.<Property Name>!= null && c.<Property Name>.Contains(search string));















VS Code # Warning - npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead

Error : VS Code - NPM Warning - npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead Solution:  Foll...