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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:45:31+00:00 2026-06-14T08:45:31+00:00

I am trying to write a simple QueryProvider for a selection and keep failing.

  • 0

I am trying to write a simple QueryProvider for a selection and keep failing. This is my example query:

var query = from elem in MyIQueryableImplementation
            select new {Name = elem.Name};

It is followed by a foreach statement that calls:

public IEnumerator<T> GetEnumerator()
{
    return ((IEnumerable<T>)this.provider.Execute(this.expression)).GetEnumerator();
}

Which invokes (ignoring the expression tree for now):

public override object Execute(Expression expression)
{
       return Exec();
}

And then:

public static IEnumerable<object> Exec()
{
     for(int i = 0; i < 10; i++)
     {
        yield return new {Name = "TEST"};
     } 
     yield break;
}

Running this, it throws the exception (in the GetEnumerator() call):

Unable to cast object of type '<Exec>d__0' to type 'System.Collections.Generic.IEnumerable`1[<>f__AnonymousType0`1[System.String]]'.

How do I fix this?

  • 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-14T08:45:32+00:00Added an answer on June 14, 2026 at 8:45 am

    The IEnumerable returned from Exec is an IEnumerable<object>. It happens to return elements of a type derived from object, but its interface type is just IEnumerable<object>. That’s why you can’t cast it to IEnumerable1[<>f__AnonymousType01[System.String]].

    You can cast it element-wise, though:

    return ((IEnumerable)this.provider.Execute(this.expression)).Cast<T>().GetEnumerator();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi trying to write a simple linq query from a tutorial I read. But
I trying to write a simple function to call unmanaged code from managed code.
I'm trying to write a simple program to calculate betweeness using brandes_betweenness_centrality from boostlib.
I'm trying write a simple perl script that reads some fields from a password
I am trying to write a simple test method to copy a file from
I am trying to write a simple program that reads integers from a data
I am trying to write a simple stream, streaming everything from a mysql field.
I am trying to write a simple Ruby program that I will run from
I'm trying write simple notify app in bash. I want to read output from
I'am trying to write simple script that will get files name from one folder

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.