The problem is casting it to string. Select()
returns IEnumerable<T>
so you are basically converting an enumerator to a string (as the error message says). Call First()
or Single()
or Take(1)
in order to get a single element before casting it to a string.
.Select(node => node.Attributes["src"].Value).First().ToString();
Also, if there is a chance that the desired element is not present, FirstOrDefault()
and SingleOrDefault()
returns null rather then throwing an exception. In that case, I would recommend
var imageUlr = ... .Select(node => node.Attributes["src"].Value).FirstOrDefault();
if (imageUrl != null)
{
// cast it to string and do something with it
}