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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:47:56+00:00 2026-05-22T02:47:56+00:00

I am using LINQ to XML to take some data from resources , and

  • 0

I am using LINQ to XML to take some data from resources , and here I have a function, where I take some values and then I create a new object (Type Translation), so when I call the function I get a Translation object. By now I have this code:

     Public Shared Function RetrieveTranslation(ByVal file As String) As List(Of clsTranslation)
    Dim valuetrans = From vl In XElement.Load(file).Elements("data") Select (New clsTranslation With {.Filename = file, .Value = vl.Element("value").Value, .TranslationId = vl.Attribute("name").Value})
    Return valuetrans
End Function

The problem is that with this code I got this error:
Unable to cast object of type ‘WhereSelectEnumerableIterator2[System.Xml.Linq.XElement,clsTranslation]' to type 'System.Collections.Generic.List1[clsTranslation]’.

Do you know the way to cast it?
Thanks in advance,

Alfonso.

  • 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-22T02:47:57+00:00Added an answer on May 22, 2026 at 2:47 am

    If you were compiling with Option Strict on, you’d have found this out at compile time.

    You don’t cast it – you call ToList() on the result, to create a List<clsTranslation> from the IEnumerable<clsTranslation>.

    (I’d also advise you to ditch the cls prefix; it goes against the .NET naming conventions.)

    That would leave:

    Public Shared Function RetrieveTranslation(ByVal file As String) _
            As List(Of Translation)
        Return (From vl In XElement.Load(file).Elements("data") _
                Select (New Translation With { _
                                   .Filename = file, _
                                   .Value = vl.Element("value").Value, _
                                   .TranslationId = vl.Attribute("name").Value}) _
               ).ToList()
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Linq to XML to create a new XML file. Some part of
How to write binary data into XML using LINQ which is being read from
I have an xml file from which I am extracting html using LINQ to
I am using Linq To Xml to create an Xml file from DataSet. This
Using Linq To XML, how can I get the space_id value (720) from the
I am using Linq to XML for some HTML output files. I need to
I'm trying to create a sitemap using Linq to Xml, but am getting an
Using LINQ to XML, how can I join two sets of data based on
I have been using Linq to XML for a few hours and while it
I am using Linq To XML to create XML that is sent to a

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.