Thursday 20 January 2011

does not contain a definition for 'SingleOrDefault'

I was calling the LINQ function SingleOrDefault, from code copied elsewhere on objects of the exact same type, so was baffled to recieve this message:

(ObjectType) does not contain a definition for 'SingleOrDefault'

A little googling revealed that all i had to do was make a reference to the System.Linq DLL for the class using the function, as such:

using System.Linq;

And all was well!

3 comments:

  1. thanks, I encountered the same problem and untill found your post..

    ReplyDelete
  2. This helped me as well. Thank you!

    Was faked out by having previously included System.XML.Linq....

    ReplyDelete