Note that there are some explanatory texts on larger screens.

plurals
  1. POAn exception of type 'AutoMapper.AutoMapperMappingException' occurred in AutoMapper.dll but was not handled in user code
    primarykey
    data
    text
    <p>Somehow my code doesn't work any more (it did work before with the exact same code). This is the problem:</p> <p><strong>The code</strong></p> <p>I'm trying to map some objects to ViewModels with this code:</p> <p>Configuration:</p> <pre><code>Mapper.CreateMap&lt;BookcaseItem, FoundBookcaseItemViewModel&gt;() .ForMember(x =&gt; x.Title, opt =&gt; opt.MapFrom(src =&gt; src.Book.Title)) .ForMember(x =&gt; x.Authors, opt =&gt; opt.MapFrom(src =&gt; src.Book.Authors.Select(x =&gt; x.Name).Aggregate((i, j) =&gt; i + ", " + j))) .ForMember(x =&gt; x.Identifiers, opt =&gt; opt.MapFrom(src =&gt; (!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 =&gt; x.Pages, opt =&gt; opt.MapFrom(src =&gt; src.Book.Pages)) .ForMember(x =&gt; x.ImageUri, opt =&gt; opt.MapFrom(src =&gt; src.Book.ThumbnailUriSmall)); </code></pre> <p>The usage:</p> <pre><code>public ActionResult Index() { string facebookId = _accountService.GetLoggedInUserFacebookId(); IEnumerable&lt;BookcaseItem&gt; items = _bookcaseItemService.GetBookcaseItemsForUser(facebookId); IEnumerable&lt;FoundBookcaseItemViewModel&gt; viewModels = items.Select(Mapper.Map&lt;BookcaseItem, FoundBookcaseItemViewModel&gt;); return PartialView(viewModels); } </code></pre> <p><strong>The error</strong></p> <p>This results in the following error:</p> <blockquote> <p>An exception of type 'AutoMapper.AutoMapperMappingException' occurred in AutoMapper.dll but was not handled in user code</p> </blockquote> <p><strong>The debug data</strong></p> <p>First of all I ensure that there are no configuration errors by calling:</p> <pre><code>Mapper.AssertConfigurationIsValid(); </code></pre> <p>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:</p> <blockquote> <p>Mapping types: BookcaseItem_B9B52593B2659AC05C47AB2A6E0F7AEA9989CC34D3527DF5B6AA988ED57166FB -> String System.Data.Entity.DynamicProxies.BookcaseItem_B9B52593B2659AC05C47AB2A6E0F7AEA9989CC34D3527DF5B6AA988ED57166FB -> System.String</p> <p>Destination path: FoundBookcaseItemViewModel.Authors</p> <p>Source value: System.Data.Entity.DynamicProxies.BookcaseItem_B9B52593B2659AC05C47AB2A6E0F7AEA9989CC34D3527DF5B6AA988ED57166FB</p> </blockquote> <p>And then there's a stacktrace property that says:</p> <blockquote> <p>at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()</p> <p>at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()</p> </blockquote> <p>Oh and finally there's another property called 'context' with the following data:</p> <p><img src="https://i.stack.imgur.com/ornAS.png" alt="enter image description here"></p> <p>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.</p> <p><strong>My setup</strong></p> <ul> <li>Visual Studio 12 RC</li> <li>ASP.NET MVC 4</li> <li>.NET Framework 4.0 (I had 4.5 but that caused too many errors, so I rolled back with Git to version 4.0)</li> <li>Entity Framework 5.0 RC</li> <li>AutoMapper 2.1.267</li> </ul> <p><strong>The entity and ViewModel</strong></p> <p>I don't know if it's relevant, but here is the source class for the mapping:</p> <pre><code>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"; } } </code></pre> <p>And this is the destination class for the mapping:</p> <pre><code>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; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload