Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6826223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:07:17+00:00 2026-05-26T22:07:17+00:00

I am currently using this page http://www.silverlightshow.net/items/Silvester-A-Silverlight-Twitter-Widget.aspx to make a Silverlight application that gets

  • 0

I am currently using this page http://www.silverlightshow.net/items/Silvester-A-Silverlight-Twitter-Widget.aspx to make a Silverlight application that gets a users twitter feed and displays it.

I have made some changes to the code but it should still work the same. However, I am receiving this error message when I try to convert the xml:

>System.NullReferenceException was unhandled by user code
  Message=Object reference not set to an instance of an object.
  Source=USElab.Web
  StackTrace:
       at USElab.Web.TwitterWebService.<GetUserTimeline>b__1(XElement status) in H:\USE\USE\USE\USElab\USElab.Web\TwitterWebService.asmx.cs:line 58
       at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at USElab.Web.TwitterWebService.GetUserTimeline(String twitterUser, String userName, String password) in H:\USE\USE\USE\USElab\USElab.Web\TwitterWebService.asmx.cs:line 57
  InnerException: 

I can’t work out why this is happening. Here is the code:

   namespace USElab.Web
   {
/// <summary>
/// Summary description for TwitterWebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]

public class TwitterWebService : System.Web.Services.WebService
{
    private const string UserTimelineUri = "http://twitter.com/statuses/user_timeline/{0}.xml";
    private const string StatusElementName = "status";
    private const string CreatedAtElementName = "created_at";
    private const string TextElementName = "text";
    private const string ProfileImageUrlElementName = "profile_image_url";
    private const string NameElementName = "name";
    private const string UserElementName = "user";
    private const string UserUrlElementName = "url";
    public const int RequestRateLimit = 70;

    [WebMethod]
        public List<TwitterItem> GetUserTimeline( string twitterUser, string userName, string password )
        {
              if ( string.IsNullOrEmpty( twitterUser ) )
              {
                  throw new ArgumentNullException( "twitterUser", "twitterUser parameter is mandatory" );
              }

              WebRequest rq = HttpWebRequest.Create( string.Format( UserTimelineUri, twitterUser ) );

              if ( !string.IsNullOrEmpty( userName ) && !string.IsNullOrEmpty( password ) )
              {
                  rq.Credentials = new NetworkCredential( userName, password );
              }

              HttpWebResponse res = rq.GetResponse() as HttpWebResponse;

              // rate limit exceeded
              if ( res.StatusCode == HttpStatusCode.BadRequest )
              {
                  throw new ApplicationException( "Rate limit exceeded" );
              }

              XDocument xmlData = XDocument.Load(XmlReader.Create(res.GetResponseStream()));
              List<TwitterItem> data = (from status in xmlData.Descendants(StatusElementName)
                           select new TwitterItem
                           {
                               Message = status.Element(StatusElementName).Element(TextElementName).Value.Trim(),
                               ImageSource = status.Element(StatusElementName).Element(ProfileImageUrlElementName).Value.Trim(),
                               UserName = status.Element(StatusElementName).Element(UserElementName).Value.Trim()
                           }).ToList();



                return data;
          }

According to the debugger, this is happening the line that starts select new TwitterItem.

Any help would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:07:18+00:00Added an answer on May 26, 2026 at 10:07 pm

    NullReferenceException usually occurs when you try to do something like null.Member

    You got pretty advanced code of creating TwitterItems , extract it to another method and perform null checks on all possible null objects (elements ins your case)before you call member functions like .Element .Value or .Trim()

    also check that xmlData isnt null before you call .Descendants on it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: I'm using Google Chrome Currently I have this test page http://www.evecakes.com/doodles/canvas_size_issue.htm It should
I'm currently using this method in calling batch files in vb.net: Private Sub Button3_Click(ByVal
I'm currently using jQuery to make a div clickable and in this div I
I'm currently using the confirmaction jQuery plugin found here: http://www.webstuffshare.com/2010/03/jquery-plugin-jconfirmaction/ And my question is
On this page with captcha demo: http://www.tutorialcadet.com/demo/ajaxform/ the captcha image is not refreshing (when
I am currently using jQuery carouses on my website http://www.ambassadorsofnowhere.com . But when the
I'm currently using this jQuery validate plugin and having an issue in IE where
I'm currently using this code to calculate the sunrise / sunset times. (To be
I am a rank beginner in C#. I am currently using this code: objGraphics.Clear(SystemColors.Control);
I'm currently using DPack as this adds a Collapse All Projects option to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.