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

  • Home
  • SEARCH
  • 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 8090945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:53:44+00:00 2026-06-05T19:53:44+00:00

Somehow my code doesn’t work any more (it did work before with the exact

  • 0

Somehow my code doesn’t work any more (it did work before with the exact same code). This is the problem:

The code

I’m trying to map some objects to ViewModels with this code:

Configuration:

Mapper.CreateMap<BookcaseItem, FoundBookcaseItemViewModel>()
    .ForMember(x => x.Title, opt => opt.MapFrom(src => src.Book.Title))
    .ForMember(x => x.Authors, opt => opt.MapFrom(src => src.Book.Authors.Select(x => x.Name).Aggregate((i, j) => i + ", " + j)))
    .ForMember(x => x.Identifiers, opt => opt.MapFrom(src => (!string.IsNullOrEmpty(src.Book.Isbn10) ? ("ISBN10: " + src.Book.Isbn10 + "\r\n") : string.Empty) +
                                                                (!string.IsNullOrEmpty(src.Book.Isbn13) ? ("ISBN13: " + src.Book.Isbn13) : string.Empty)))
    .ForMember(x => x.Pages, opt => opt.MapFrom(src => src.Book.Pages))
    .ForMember(x => x.ImageUri, opt => opt.MapFrom(src => src.Book.ThumbnailUriSmall));

The usage:

public ActionResult Index()
{
    string facebookId = _accountService.GetLoggedInUserFacebookId();

    IEnumerable<BookcaseItem> items = _bookcaseItemService.GetBookcaseItemsForUser(facebookId);
    IEnumerable<FoundBookcaseItemViewModel> viewModels = items.Select(Mapper.Map<BookcaseItem, FoundBookcaseItemViewModel>);

    return PartialView(viewModels);
}

The error

This results in the following error:

An exception of type ‘AutoMapper.AutoMapperMappingException’ occurred in AutoMapper.dll but was not handled in user code

The debug data

First of all I ensure that there are no configuration errors by calling:

Mapper.AssertConfigurationIsValid();

I’ve set breakpoints all over my code and try to debug it, but I can’t make sense of it. The ‘items’ collection is filled with data (proxy classes generated by Entity Framework), but the the ‘viewModels’ collection is filled with strange data. It has a ‘message’ that says this:

Mapping types:
BookcaseItem_B9B52593B2659AC05C47AB2A6E0F7AEA9989CC34D3527DF5B6AA988ED57166FB
-> String System.Data.Entity.DynamicProxies.BookcaseItem_B9B52593B2659AC05C47AB2A6E0F7AEA9989CC34D3527DF5B6AA988ED57166FB
-> System.String

Destination path: FoundBookcaseItemViewModel.Authors

Source value:
System.Data.Entity.DynamicProxies.BookcaseItem_B9B52593B2659AC05C47AB2A6E0F7AEA9989CC34D3527DF5B6AA988ED57166FB

And then there’s a stacktrace property that says:

at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()

at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()

Oh and finally there’s another property called ‘context’ with the following data:

enter image description here

Can anyone explain what’s going on here and why my code isn’t working any longer? I did a couple of changes to my solution recently, but I’ve rolled them back by Git, so they shouldn’t have any effect on the code.

My setup

  • Visual Studio 12 RC
  • ASP.NET MVC 4
  • .NET Framework 4.0 (I had 4.5 but that caused too many errors, so I rolled back with Git to version 4.0)
  • Entity Framework 5.0 RC
  • AutoMapper 2.1.267

The entity and ViewModel

I don’t know if it’s relevant, but here is the source class for the mapping:

public class BookcaseItem : Entity
{
    public Guid Id { get; set; }
    public bool IsRenting { get; set; }
    public bool IsSwapping { get; set; }
    public bool IsSelling { get; set; }
    public decimal RentingPrice { get; set; }
    public decimal SellingPrice { get; set; }
    public string Currency { get; set; }
    public bool IsAvailable { get; set; }
    public virtual Guid BookId { get; set; }
    public virtual Guid UserId { get; set; }

    public virtual Book Book { get; set; }
    public virtual User User { get; set; }

    public BookcaseItem()
    {
        IsAvailable = true;
        Currency = "USD";
    }
}

And this is the destination class for the mapping:

public class FoundBookcaseItemViewModel
{
    public Guid Id { get; set; }
    public bool IsRenting { get; set; }
    public bool IsSwapping { get; set; }
    public bool IsSelling { get; set; }
    public decimal RentingPrice { get; set; }
    public decimal SellingPrice { get; set; }
    public string Title { get; set; }
    public string Authors { get; set; }
    public string Identifiers { get; set; }
    public int Pages { get; set; }
    public string ImageUri { get; set; }
}
  • 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-05T19:53:45+00:00Added an answer on June 5, 2026 at 7:53 pm

    It seems like there is a problem with mapping Authors property. This Aggregate call will throw an exception if the Authors sequence is null or empty.

    .ForMember(x => x.Authors, 
               opt => opt.MapFrom(src => src.Book.Authors.Select(x => x.Name).Aggregate((i, j) => i + ", " + j)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code doesn't work, somehow I can't get the int value from the
Somehow it doesn't work, according to me it should be this: public void Splash(){
I found the self.moveBy function here . Somehow the code doesn't seem to work
I have this code to change system time. This code works but somehow doesn't
is this good code? can it be simplified somehow? SELECT u.id,u.title,u.title,u.first,u.last FROM (((tblusers u
I have this code: NSMutableData *derivedKey = [NSMutableData dataWithLength:32]; // code missing..fill somehow the
i've built this sample code based on a real problem I have in an
I have a static method in my code that I would like somehow to
somehow I get never any results when I call: select * from table_1 t1
Somehow I managed to make the date work, <td width=67><font size=3><b>*Date</b></td> <td width=3>:</td> <td

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.