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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:44:37+00:00 2026-06-02T17:44:37+00:00

So, here’s my situation. I’ve got a my two classes: class FromClass { public

  • 0

So, here’s my situation. I’ve got a my two classes:

class FromClass
{
    public string[] Foo { get; set; }
}

class ToClass
{
    public string[] Foo { get; set; }
}

The classes have properties which are arrays. They could be List<T> or IEnumerable<T>, I get the same result in any of those cases.

I try to map from one to the other using the AutoMapper.QueryableExtensions:

class Program
{
    static void Main(string[] args)
    {
        // create a "From" object
        string[] anArray = new string[] { "a", "b" };
        FromClass anObject = new FromClass() { Foo = anArray };

        // make a queryable set that includes the "From" object
        IQueryable<FromClass> queryableObjects = (new FromClass[] { anObject }).AsQueryable();

        // set up AutoMapper
        Mapper.CreateMap<FromClass, ToClass>();
        Mapper.AssertConfigurationIsValid();

        // test plain mapping
        IQueryable<ToClass> test1 = queryableObjects.Select(o => Mapper.Map<FromClass, ToClass>(o));
            // success!

        // test queryable extensions
        IQueryable<ToClass> test2 = queryableObjects.Project().To<ToClass>();
            // InvalidOperationException: "Sequence contains no elements"

    }
}

Why does test2 throw an InvalidOperationException? If I make the type of Foo something that’s not a collection, e.g. a string or some other class — then everything works perfectly.

Am I doing something wrong? Not understanding something? Or have I hit a bug?

  • 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-02T17:44:38+00:00Added an answer on June 2, 2026 at 5:44 pm

    I would say: this is a bug: see Github Issue 159.

    The AutoMapper.QueryableExtensions uses Mapper.CreateMapExpression internally so if you write:

    var expression = Mapper.CreateMapExpression<FromClass, ToClass>();
    

    It will also fail with the same exception.

    It seems Mapper.CreateMapExpression currently does not support:

    • generic collections of value types e.g. List<string> etc.
    • arrays of complex types or value types e.g string[], Bar[] etc.

    But if you make your Foo to List<Item> it can work:

    public class FromClass
    {
        public List<Item> Foo { get; set; }
    }
    
    public class ToClass
    {
        public List<Item> Foo { get; set; }
    }
    
    public class Item
    {
        public string Bar { get; set; }
    }
    
    var list =  new List<Item> { new Item{ Bar = "a"}, new Item() { Bar= "b" }};
    FromClass anObject = new FromClass() { Foo = list };
    var queryableObjects = (new FromClass[] { anObject }).AsQueryable();
    Mapper.CreateMap<FromClass, ToClass>();
    Mapper.CreateMap<Item, Item>();
    var test2 = queryableObjects.Project().To<ToClass>().ToArray();
    

    You can comment on the above mentioned issue or create a new one with your code (it’s a quite good repro of the bug)

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

Sidebar

Related Questions

Here's my situation: I have a Data Template set up which contains a ToggleButton
Here is the situation, I am attempting to fire a set of Gallio tests
Here is my situation: I am using telerik with winform. I have a dataset
Here is my code...I have two dimensional matrices A,B. I want to develop the
Here is what I am trying to achieve in PHP: I have this string:
Here is my problem...I have a page that loads a list of clients and
Here is some code I made :) @echo off set source=R:\Contracts\ set destination=R:\Contracts\Sites\ ROBOCOPY
Here is an example: I have a file 1.js, which has some functions. I
Here is the piece of code which I use to get the count from
Here's the basic setup: I have a thin bar at the top of 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.