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

  • SEARCH
  • Home
  • 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 7721501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:56:26+00:00 2026-06-01T03:56:26+00:00

I can’t understand why object is null: WebClient browse = new WebClient(); StreamReader res

  • 0

I can’t understand why object is null:

        WebClient browse = new WebClient();
        StreamReader res = new StreamReader(browse.OpenRead("http://ws.audioscrobbler.com/2.0/?method=track.getinfo&api_key=b25b959554ed76058ac220b7b2e0a026&artist=cher&track=believe"));
        string result = res.ReadToEnd();

        XmlDocument xmltrackinfo = new XmlDocument();
        xmltrackinfo.InnerXml = result;



        XmlRootAttribute xRoot = new XmlRootAttribute();
        xRoot.ElementName = "lfm";
        xRoot.IsNullable = true;

        XmlSerializer xs = new XmlSerializer(typeof(fm), xRoot);

        fm rez = (fm) xs.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(result)));

Object Model:

[Serializable()]
[XmlRoot(ElementName = "lfm", IsNullable = true)]
public class fm
{
    [XmlElement("lfm")]
    public Track lfm { get; set; }
}

[Serializable()]
[XmlRoot(ElementName = "artist", IsNullable = true)]
public class artist
{
    public string name { get; set; }
    public string mbid { get; set; }
    public string url { get; set; }
}

[Serializable()]
[XmlRoot(ElementName = "album", IsNullable = true)]
public class album
{
    public string artist { get; set; }
    public string title { get; set; }
    public string mbid { get; set; }
    public string url { get; set; }
    public List<string> image { get; set; }
}

[Serializable()]
[XmlRoot(ElementName = "tag", IsNullable = true)]
public class tag
{
    public string name { get; set; }
    public string url { get; set; }

}

[Serializable()]
[XmlRoot(ElementName = "wiki", IsNullable = true)]
public class wiki
{
    public string summary { get; set; }
    public string content { get; set; }
}

[Serializable()]
[XmlRoot(ElementName = "track", IsNullable = true)]
public class Track
{
    public string id { get; set; }
    public string name { get; set; }
    public string mbid { get; set; }
    public string url { get; set; }
    public string duration { get; set; }
    public string streamable { get; set; }
    public string listeners { get; set; }
    public string playcount { get; set; }
    public artist artist { get; set; }
    public album album { get; set; }
    public List<tag> toptags { get; set; }
    public wiki wiki { get; set; }

}

and XML:

http://ws.audioscrobbler.com/2.0/?method=track.getinfo&api_key=b25b959554ed76058ac220b7b2e0a026&artist=cher&track=believe

so what should I do?

  • 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-06-01T03:56:28+00:00Added an answer on June 1, 2026 at 3:56 am

    Try renaming your fm class to lfm.

    public class lfm
    {
        public Track track { get; set; }
    }
    

    and then you could also get rid of the xRoot variable:

    XmlSerializer xs = new XmlSerializer(typeof(lfm));
    lfm rez = (lfm) xs.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(result)));
    

    Also you don’t need the [Serializable] attribute. This is used for binary serialization and is completely ignored by the XmlSerializer class.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can you guys help me understand a concept real quick, I'm having trouble understanding
Can I register a .Net COM class with the SingleUse -flag? The reason I
can anyone tell me if it is possible to convert a dojo charting object
can anyone tell me why this doesn't work? db = openOrCreateDatabase(database.db, SQLiteDatabase.CREATE_IF_NECESSARY, null); db.setLocale(Locale.getDefault());
Can you set the internal [[Class]] property of an ECMAScript object?
Can somebody point me to a resource that explains how to go about having
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can you cast a List<int> to List<string> somehow? I know I could loop through
can you recommend some good ASP.NET tutorials or a good book? Should I jump

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.