Posted on: 3/20/2015 2:31:04 PM | Views : 635

Hi, 
I have a site that uses LINQ to SQL to return some result from a database
public static List<Products> GetBySearchID(int SearchID) { using (MyContext ctx = new MyContext(connstrng) { return DoSomeProcessing(cts.Searcheds.Where(x => x.ID == SearchID).FirstOrDefault(), ctx); } } This works, although on rare occasions it will throw the following error:
System.NullReferenceException: Object reference not set to an instance of an object. at MyPricing.Object.DTOPrice..ctor(ufn_GetPriceResult p, DTOPrice parent) at MyPricing.Object.DTOPricing..ctor(List`1 p, DTOProductPrice parent) at ProductManager.<>c__DisplayClass13.<DoSomeProcessing>b__7(IGrouping`2 grp) at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource] ...

Go to the complete details ...