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 6218175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:33:35+00:00 2026-05-24T07:33:35+00:00

I am totally stumped on this one. I am getting a Object reference not

  • 0

I am totally stumped on this one. I am getting a “Object reference not set to an instance of an object.” error – but I can’t figure out why. This is the code that I have:

        public class PlayerProfile
    {
        public List<Profile> PlayerINfo = new List<Profile>();


        public void LoadProfiles(string path)
        {
            XDocument xmlDoc = XDocument.Load(path);
            PlayerINfo = new List<Profile>();

// This is where I get the error:
            PlayerINfo = (from profiles in xmlDoc.Root.Element("OnlineProfile").Elements("Player")
                              select new Profile
                              {
                                  Name = (string)profiles.Element("Name"),
                                  Sex = (string)profiles.Element("Sex"),
                                  Avatar = (string)profiles.Element("Avatar").Attribute("path") ?? "",
                                  Created = (DateTime)profiles.Element("Created")
                              }).ToList();


        }
    }

Here is my Profile class:

    public class Profile
{
    public string Name { get; set; }
    public string Sex { get; set; }
    public string Avatar { get; set; }
    public DateTime Created { get; set; }

}

EDIT – Adding the XML file code:

    <?xml version="1.0" encoding="utf-8"?>
<OnlineProfile>
  <Player>
    <Name>Stacey</Name>
    <Sex>Female</Sex>
    <Avatar path="/images/Picture.png" />
    <Ratio>
      <Win>0</Win>
      <Loss>0</Loss>
      <Abandoned>0</Abandoned>
    </Ratio>
    <Created>6/19/2011</Created>
  </Player>

</OnlineProfile>
  • 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-24T07:33:36+00:00Added an answer on May 24, 2026 at 7:33 am

    Do this: from profiles in xmlDoc.Element("OnlineProfile").Elements("Player") instead of from profiles in xmlDoc.Root.Element("OnlineProfile").Elements("Player")

    From the XML you posted “OnlineProfile” is your Root element, so the child elements you expect arent there.

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

Sidebar

Related Questions

So I'm totally stumped by this one and tempted to call OS bug. I
Hope someone can help me with this, it has me totally stumped My application
I'm getting a totally bizzare error trying to compile a C program using GCC.
I am totally new to XSLT and can't work out where I am going
UPDATE So totally pulled a tool moment. I really meant by reference versus Out/Ref.
Are there any good books for a relatively new but not totally new *nix
This one has me stumped. I've got a java.sql.ResultSet and I'm pulling string values
I am totally in confusion. Apple told that in iPhone 4 one can use
Im not totally sure how to do this in HTML as im not fully
Totally stupid question, but I'm writing my first ASP.NET C# web forms application and

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.