Question

I'm trying to get the thumbnail from an atom feed from youtube. Here is my code:

XNamespace atom = "http://www.w3.org/2005/Atom";
XNamespace media = "http://search.yahoo.com/mrss/";
var YTitems = from entry in document.Descendants(atom + "entry")
              select new RSSFeed
              {
                   Image = entry.Element(media + "thumbnail").Attribute("url").Value,
                   Title = entry.Element(atom + "title").Value,
                   Description = entry.Element(atom + "content").Value
              };
YoutubeList.ItemsSource = YTitems.ToList();

But when trying to load the feed, I am getting this error:

NullReferenceException was unhandled by user code
Object reference not set to an instance of an object

It works without the "Image = entry.element(......", so the problem is probably there. (example of the feed here.)

Was it helpful?

Solution

I fixed it by using this:

ImageSRC = entry.Element(media + "group").Element(media + "thumbnail").Attribute("url").Value
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top