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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:12:05+00:00 2026-06-07T14:12:05+00:00

I working within an older application (from 1.1 days) and there are many non-generic

  • 0

I working within an older application (from 1.1 days) and there are many non-generic collections like:

[Serializable]
public class MyEntityList : CollectionBase
{
    private int _virtualRecordCount;

    public int VirtualRecordCount
    {
        get { return _virtualRecordCount; }
        set { _virtualRecordCount = value; }
    }

    public MyEntityList()
    {
    }

    public MyEntityList(MyEntity[] arr)
    {
        AddRange(arr);
    }

    public MyEntityList this[int index]
    {
        get { return (MyEntity)InnerList[index]; }
    }

    public void Add(MyEntity item)
    {
        InnerList.Add(item);
    }

    etc...

I’ve upgraded a layer of the application to use a generic Collection<T> for the return type. This layer is auto-generated and the class names are based upon the datasource table names. The business entity classes don’t necessary line up either, but not so in this case. In this case, they match perfectly 1:1.

I tried mapping the collections like so:

Collection<MyEntityResponse> responses = GetMyEntityResponses();

AutoMapper.Mapper.CreateMap<MyEntityResponse, MyEntity>();
myEntityList = AutoMapper.Mapper.Map<MyEntityList>(responses);

The strangest thing… I thought that it might squawk at the use of CollectionBase, but I hit F5 anyway. To my suprise, no compiler error and no exception. WOOHOO!

However, later in the app it threw an exception complaining about a type conversion from MyEntityResponse to MyEntity when it tried to perform a foreach() on MyEntityList that was returned from Mapper.Map.

What happened is a new MyEntityList collection was returned but it was filled with MyEntityResponse objects. Huh?? The custom collection overrides the Add() method and specifies that the type must be of type MyEntity. I would expect it to blow up when attempting to add the wrong type to the collection, but it didn’t seem to have any issues working with CollectionBase.

So my questions are, if the two types I’m trying to map match perfectly (property to property), and AutoMapper didn’t have an issue with CollectionBase, why was it not able to map the enties? And why didn’t it throw an exception instead of shoving the wrong type into the collection?


EDIT: I think I know why… because the non-generic collection doesn’t have a known type associated with it, like the generic one does.

So, new question… how do I tell it to use MyEntity instead of MyEntityResponse ?

  • 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-07T14:12:07+00:00Added an answer on June 7, 2026 at 2:12 pm

    I think I found my answer: http://automapper.codeplex.com/wikipage?title=Lists%20and%20Arrays

    For the non-generic enumerable types, only unmapped, assignable types
    are supported, as AutoMapper will be unable to “guess” what types
    you’re trying to map. As shown in the example above, it’s not
    necessary to explicitly configure list types, only their member types.

    As of release 0.2.0, no custom destination collection types are
    supported.

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

Sidebar

Related Questions

With Twitter Bootstrap 2, how do get links working within collapse-nav: <div class=navbar navbar-fixed-top>
Ok so I am working on a calendar application within my CRM system and
I've been working through my first MVC application, and I'd like to localize it.
I'm working within a platform that I do not have server side access to
I am currently working within a WPF user control (the root element of my
I am working within an intranet environment. We have both a production and development
I'm working within zend forms. Currently this is how it looks: I want to
Why is my mkdir not working within the if(is_dir) function but it is working
I'm trying to get twitter bootstrap's .popover working within a .submit jquery event but
Attempting/struggling to get registration and sign-up working within an active admin project. I have

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.