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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:05:11+00:00 2026-05-22T01:05:11+00:00

I have an issue while trying to parse an Xml to Objects using Linq

  • 0

I have an issue while trying to parse an Xml to Objects using Linq in a Windows Phone 7 application. The same linq query works in silverlight.

Here is the xml:

<?xml version="1.0" encoding="utf-8" ?>
<students>
  <student>
    <firstName>John</firstName>
    <lastName>Doe</lastName>
  </student>
  <student>
    <firstName>Jane</firstName>
    <lastName>Doe</lastName>
  </student>
</students>

And all the code that I have is in the MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Xml.Linq;

namespace WindowsPhoneApplication2
{
    public class Student
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }

    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            XDocument doc = XDocument.Load("my1.xml");

            var test = from students in doc.Elements("students").Elements("student")
                       select new Student()
                       {
                           FirstName = students.Element("firstName").Value,
                           LastName = students.Element("lastName").Value
                       };

            foreach (var _student in test)
            { }
        }
    }
}

The error that I get is pretty weird (this is inside the foreach when you quick watch test):
System.Collections.Generic.IEnumerator.Current = Could not evaluate expression.
System.Collections.Generic.IEnumerator.Current = ‘System.Collections.Generic.IEnumerable’ does not contain a definition for ‘System’ and no extension method ‘System’ accepting a first argument of type ‘System.Collections.Generic.IEnumerable

In the mean time inside the foreach the _student var has the correct value on each iteration?! Is this error a bug? Or where is it coming from?

… :\

Edit:

Here is a screenshot of where I see the error:
enter image description here

The students collection turn out to be correct but having that error there frightens me for when i will push out an application to the App Market.

If it helps i am using the emulator to debug.

EDIT:
I’m adding this screenshot based on Desnnis’s response.

enter image description here

  • 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-22T01:05:12+00:00Added an answer on May 22, 2026 at 1:05 am

    First of all add a reference to System.Linq in the class header. As in:

    using System.Linq;
    

    The problem in your case is that you are setting the breakpoint at the beginning of the foreach loop when nothing is selected. Create an action inside the loop and set a breakpoint there. You will see that the values will have a Student instance.

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

Sidebar

Related Questions

We have an issue using the PEAR libraries on Windows from PHP . Pear
I have an issue that is driving me a bit nuts: Using a UserProfileManager
We have an issue related to a Java application running under a (rather old)
I have an issue with using AWK to simply remove a field from a
I have a strange issue. I'm trying to get Apple Push Notifications working with
We have an issue on our page whereby the first time a button posts
I have some issue with a Perl script. It modifies the content of a
I have big issue with url-rewriting for IIS 7.0. I've written simple module for
We have an issue with the way we are creating a Mutex . The
I currently have an issue in my DLR language implementation where subsequent calls to

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.