You would typically get that if code uses .First()
or .Single()
on a sequence (IEnumerable<T>
) that has (as the message suggests): no elements. Meaning: an empty sequence (not to be confused with a null
sequence). You don't show code that does that, so I can only assume this happens inside .GetLatLongFromAddress()
. So it sounds like there is a bug, probably relating to the "not found" case, but in code that we can't see. Personally, I would expect the "not found" case to return a null
, or to throw some explicit "not found" exception. If this bug is inside a library: tell the library authors about it. Or better: fix it, and submit a pull request (if you can).
Edit: here we go:
XDocument doc = XDocument.Load(string.Format(APIUrlLatLongFromAddress,
Uri.EscapeDataString(address)));
var els = doc.Descendants("result").Descendants("geometry")
.Descendants("location").First();
if (null != els) {...}
IMO, that should be:
XDocument doc = XDocument.Load(string.Format(APIUrlLatLongFromAddress,
Uri.EscapeDataString(address)));
var els = doc.Descendants("result").Descendants("geometry")
.Descendants("location").FirstOrDefault();
if (null != els) {...}
One line code fix to send them...
GoogleLocationService
is a service class name fromGoogleMaps.LocationServices
dll