0

What I am trying to do Is, find an object inside a list

Log q = logs.Find(x => (x.dnsq.queryID.Contains(queryid)));

However when I do it, I get this error

x.dnsq.queryID = 'x.dnsq.queryID' threw an exception of type 'System.NullReferenceException

The Log class looks like this

class Log : LogCtrl
{
    public int id { set; get; }
    public string source { set; get; }
    public string destination { set; get; }
    public string protocol { set; get; }
    public double time { set; get; }
    public string info { set; get; }
    public DNSresponse dnsr { set; get; }
    public DNSquery dnsq { set; get; }
}
Steve
  • 11,696
  • 7
  • 43
  • 81
Mathias_
  • 323
  • 1
  • 4
  • 14

1 Answers1

2

It sounds like either x or x.dnsq or x.dnsq.queryId is null for at least one item in logs. You can check for this in your statement by doing the following:

    Log q = logs.Find(x => (x != null && x.dnsq != null && x.dnsq.queryID != null && x.dnsq.queryID.Contains(queryid)));