This project has moved. For the latest updates, please go here.


Extended Entities



I am quiet new to linq2twitter and i have a question about the ExtendedEntities:

I am trying to retrieve 2 Photos from a Status that i got from a search.

So my attempt is to search for a keyword and then i try to get the ExtendedEntities from the
Status of the search result.

So created a >Status[] SearchStatus< in tweet class.

In my SearchClass i have:

var twitterCtx = new TwitterContext(SharedState.Authorizer);
        var tweets =
            (from tweet in twitterCtx.Search
             where tweet.Type == SearchType.Search &&
               tweet.Query == TxtBxSerachQuery.Text && tweet.Count ==  numMaxTweets.Value
             select new Tweet

                 SearchStatuses = tweet.Statuses.ToArray()  


tweets.ForEach( tweet =>
       int Count = tweet.SearchStatuses.Length;

        for (int i = 0; i < Count; i++ )
          // trying to get the number of ExtendedEntities.MediaEntities 
          int NumExMedia = tweet.SearchStatuses[i].ExtendedEntities.MediaEntities.Count;


I do always get a System.NullReferenceException when it comes to the >NumExMedia<? Is there nothing in this Extended Entities ? I am searching for my own name (chriswattz) and in the first 2 results i will get the standart MediaEntities without a problem but there is just one image inside, the second one does not show up.

So i know that the ExtendedEntities.MediaEntities should contain them but i do always get a NullReferenceExpetion....someone has an idea?


Closed May 4, 2015 at 12:56 AM by JoeMayo
Modified MediaEntities to instantiate empty collection. Also, reviewed collection properties in other entities and ensured they were instantiated to manage consistency. Changes pushed to new GitHub repository at:


JoeMayo wrote Apr 2, 2015 at 6:26 PM


In the current implementation, if there are no extended entities for a tweet, the ExtendedEntities will have an instance, but it's properties will be null. In this case, I suspect MediaEntities is null, so the .Count causes the NullReferenceException.

That said, it seems like the current implementation can cause more friction for other developers encountering this. So, I've moved this to a work item. I'm thinking that a better implementation would be to instantiate an empty MediaEntities (and other *Entities collections) if there are no entities.

What do you think of that?

In the meantime, you can check for null to avoid the NullReferenceException.


chriswattz wrote Apr 2, 2015 at 6:34 PM

Hi Joe,

Thanks for your reply,

Yes i think that an empty MediaEntities etc would be a good idea.

I will check for the null to avoid the error.