RecursiveDnsResolver - Throws error because list contains no items

Mar 17, 2016 at 8:28 PM
Hi There,

It seems there's a bug in "RecursiveDnsResolver" that does a "First()" command on a list object without doing a check to see if there are objects in the list.

Here's the current code:
Lines 211-215 in RecursiveDnsResolver.cs:
List<CNameRecord> cachedCNames;
if (_cache.TryGetRecords(name, RecordType.CName, recordClass, out cachedCNames))
       return await ResolveAsyncInternal<T>(cachedCNames.First(). CanonicalName, recordType, recordClass, state, token);
I called the class using an internal domain controller, and it didn't have any CName records.
So, the method threw an error saying "No Items in Collection" (or similar).

So, please can we change Line #211 to this:
if (_cache.TryGetRecords(name, RecordType.CName, recordClass, out cachedCNames) && cachedCNames.Count > 0)