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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:29:43+00:00 2026-05-16T20:29:43+00:00

I am trying to create an instance of a class using Linq and XML.

  • 0

I am trying to create an instance of a class using Linq and XML. I am getting the following error in my code and do not know how to fix it. My code editor is telling me the “select” in the following code is the culprit. I am very new to Linq so any help is appreciated.

Cannot implicitly convert type ‘System.Collections.Generic.IEnumerable’ to ‘gcDiversityVision.VisionData’. An explicit conversion exists (are you missing a cast?)

XElement visionXML = XElement.Parse(e.Result);

            VisionData newVisionData = new VisionData(new List<string>(visionXML.Descendants(ns + "Employee").Select(f => f.Element(ns + "EmployeeName").Value)),
                                                        new List<string>(visionXML.Descendants(ns + "Employee").Select(f => f.Element(ns + "EmployeeTitle").Value)),
                                                        new List<string>(visionXML.Descendants(ns + "Employee").Select(f => f.Element(ns + "include").Attribute("externalPath").Value)),
                                                        new List<string>(visionXML.Descendants(ns + "Employee").Select(f => f.Element(ns + "EmployeeVideo").Value)),
                                                        visionXML.Element(ns + "LinkHeaderText").Value,
                                                        visionXML.Element(ns + "ButtonLinkText").Value,
                                                        visionXML.Element(ns + "ButtonLinkURL").Value,
                                                        new List<string>(visionXML.Descendants(ns + "Links").Select(f => f.Element(ns + "LinkURL").Value)),
                                                        new List<string>(visionXML.Descendants(ns + "Links").Select(f => f.Element(ns + "LinkText").Value)),
                                                        new List<string>(visionXML.Descendants(ns + "EmployeeStoryHeaderParagraph").Select(f => f.Element(ns + "EmployeeHeader").Value)),
                                                        new List<string[]>(visionXML.Descendants(ns + "EmployeeStoryHeaderParagraph").Select(f => f.Descendants(ns + "EmployeeParagraphs").Select(ep => ep.Element(ns + "EmployeeParagraph").Value).ToArray()))
                                                    );
<c:gcDiversityVision>
<c:Employee>
  <c:EmployeeName>Employee Name 1</c:EmployeeName>
  <c:EmployeeTitle>EmployeeTitle 1</c:EmployeeTitle>
  <c:EmployeeIconImage>
    <c:include type="Image" resolve="false" sourcedFrom="local" externalPath="/global/hrit/Careers/PublishingImages/down_carat.gif" height="7" width="12" query="">/hrit/Careers/PublishingImages/down_carat.gif</c:include>
  </c:EmployeeIconImage>
  <c:EmployeeVideo>mms://msnvidweb.wmod.msecnd.net/a10026/e1/ds/us/CMG_US/CMG_Microsoft/8F036573-ADAD-40B3-B2A2-A070E6C970B2.wmv</c:EmployeeVideo>
</c:Employee>
<c:Employee>
  <c:EmployeeName>Employee Name 2</c:EmployeeName>
  <c:EmployeeTitle>Employee Title 2</c:EmployeeTitle>
  <c:EmployeeIconImage>
    <c:include type="Image" resolve="false" sourcedFrom="local" externalPath="/global/hrit/Careers/PublishingImages/2nav_bg.png" height="29" width="2" query="">/hrit/Careers/PublishingImages/2nav_bg.png</c:include>
  </c:EmployeeIconImage>
  <c:EmployeeVideo>mms://msnvidweb.wmod.msecnd.net/a10026/e1/ds/us/CMG_US/CMG_Microsoft/BE4A3DF0-15FB-4610-A478-F681FCBE2DFA.wmv</c:EmployeeVideo>
</c:Employee>
<c:VisionParagraph>
  <c:VisionHeaderParagraph>
    <c:VisionHeader>Vision Header 1</c:VisionHeader>
    <c:VisionParagraphs>
      <c:VisionParagraph>Vision Paragraph 1.1</c:VisionParagraph>
    </c:VisionParagraphs>
    <c:VisionParagraphs>
      <c:VisionParagraph>Vision Paragraph 1.2</c:VisionParagraph>
    </c:VisionParagraphs>
  </c:VisionHeaderParagraph>
  <c:VisionHeaderParagraph>
    <c:VisionHeader>Vision Header 2</c:VisionHeader>
    <c:VisionParagraphs>
      <c:VisionParagraph>Vision Paragraph 2.1</c:VisionParagraph>
    </c:VisionParagraphs>
    <c:VisionParagraphs>
      <c:VisionParagraph>Vision Paragraph 2.2</c:VisionParagraph>
    </c:VisionParagraphs>
  </c:VisionHeaderParagraph>
</c:VisionParagraph>
<c:Footer>
  <c:Button>
    <c:ButtonLinkText>Button Link Text</c:ButtonLinkText>
    <c:ButtonLinkURL>http://www.bing.com/</c:ButtonLinkURL>
  </c:Button>
  <c:LinkHeaderText>Link Text 2</c:LinkHeaderText>
  <c:Links>
    <c:LinkText>Link Text 1</c:LinkText>
    <c:LinkURL>http://www.bing.com/</c:LinkURL>
  </c:Links>
  <c:Links>
    <c:LinkText>Link Text 2</c:LinkText>
    <c:LinkURL>http://www.bong.com/</c:LinkURL>
  </c:Links>
  <c:Links>
    <c:LinkText>Link Text 3</c:LinkText>
    <c:LinkURL>http://www.bing.com/</c:LinkURL>
  </c:Links>
  <c:Links>
    <c:LinkText>Link Text 4</c:LinkText>
    <c:LinkURL>http://www.bong.com/</c:LinkURL>
  </c:Links>
</c:Footer>

  • 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-16T20:29:43+00:00Added an answer on May 16, 2026 at 8:29 pm

    You’ve told it to create a new VisonData for each gcDiversityVision element in your document. The result is therefore a sequence of VisionData objects.

    What are you actually trying to do – create one, or create many? There are lots of options available – if you give us more information about what you’re trying to do, we can help you more.

    Assuming you own the VisionData class, I would also suggest that you write a static VisionData.FromXElement method (or put it somewhere else) so that your query isn’t quite so huge.

    EDIT: Okay, based on the comment, it sounds like you don’t want a LINQ query at all. Just:

    XElement root = visionXml.Root;
    VisionData newVisionData = new VisionData(...);
    

    By the way, if you use the ToList extension method rather than new List<string>(...) it’s likely to make the query a bit simpler. Or change the VisionData constructor to accept parameters of type IEnumerable<string> instead of List<string>, so you don’t need to do the conversion within your constructor call at all.

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

Sidebar

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.