title: Automapper AutoMapper.AutoMapperMappingException: Error mapping types
body: <p>I am getting a peculiar error with Automapper</p>
  
  <p>Error messages:</p>
  
  <pre><code>Mapping types:
  TransportOffer -&gt; TransportOfferDto
  Model.TransportOffer -&gt; Dto.TransportOfferDto
  
  Type Map configuration:
  TransportOffer -&gt; TransportOfferDto
  Model.TransportOffer -&gt; Dto.TransportOfferDto
  
  Property:
  FromCity ---&gt; AutoMapper.AutoMapperMappingException: Error mapping types.
  
  Mapping types:
  City -&gt; CityDto
  Model.City -&gt; Dto.CityDto
  
  Type Map configuration:
  City -&gt; CityDto
  Model.City -&gt; Dto.CityDto
  
  Property:
  Country ---&gt; System.TypeLoadException: Method 'Add' in type 'Proxy_System.Collections.Generic.ICollection`1[[Dto.CountryDto, BusinessLogic, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]__17474517' from assembly 'AutoMapper.Proxies, Version=0.0.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005' does not have an implementation.
  </code></pre>
  
  <p>Below are my entities and DTO and the query that retrieves the data.
  I am using Automapper 7.0.1 and Automapper.Attributes 6.0.1</p>
  
  <p>I have tried also with custom mapping configuration and the error is the same.</p>
  
  <p>Here is the Automapper custom property configuration:</p>
  
  <pre><code>Mapper.Initialize
  (
      config =&gt;
      {
          config.CreateMap&lt;TransportOfferDto, TransportOffer&gt;()
              .ForMember(dest =&gt; dest.FromCity, conf =&gt; conf.MapFrom(src =&gt; src.FromCity))
              .ForMember(dest =&gt; dest.FromCountry, conf =&gt; conf.MapFrom(src =&gt; src.FromCountry))
              .ForMember(dest =&gt; dest.ToCity, conf =&gt; conf.MapFrom(src =&gt; src.ToCity))
              .ForMember(dest =&gt; dest.ToCountry, conf =&gt; conf.MapFrom(src =&gt; src.ToCountry));
           }
       );
  </code></pre>
  
  <blockquote>
    <p>Country - entity:</p>
  </blockquote>
  
  <pre><code>public class Country : BaseEntity&lt;Int32&gt;
  {        
      public string Name { get; set; }
      public string Code { get; set; }
      public string Capital { get; set; }
      public Int32 TotalSold { get; set; }
  }
  </code></pre>
  
  <blockquote>
    <p>CountryDto</p>
  </blockquote>
  
  <pre><code>[MapsTo(typeof(Country))]
  [MapsFrom(typeof(Country))]
  public class CountryDto : EntityDto&lt;Int32&gt;
  {
      public string Name { get; set; }
      public string Code { get; set; }
      public string Capital { get; set; }
      public Int32 TotalSold { get; set; }
  }
  </code></pre>
  
  <blockquote>
    <p>City - entity:</p>
  </blockquote>
  
  <pre><code>public class City : BaseEntity&lt;Int32&gt;
  {        
      public string Name { get; set; }
      public Int32 CountryID { get; set; }
      public virtual Country Country { get; set; }
  }
  </code></pre>
  
  <blockquote>
    <p>CityDto</p>
  </blockquote>
  
  <pre><code>[MapsTo(typeof(City))]
  [MapsFrom(typeof(City))]
  public class CityDto : EntityDto&lt;Int32&gt;
  {
      public Int32 CountryID { get; set; }
      public virtual ICollection&lt;CountryDto&gt; Country { get; set; }
  
      public string Name { get; set; }
  
  }
  </code></pre>
  
  <blockquote>
    <p>TransportOffer - entity:</p>
  </blockquote>
  
  <pre><code>public class TransportOffer : BaseEntity&lt;Guid&gt;
  {
      public Guid TransportToken { get; set; }
      public DateTime Date { get; set; }
      public Int32 FromCityID { get; set; }
      public  virtual City FromCity { get; set; }
      public Int32 FromCountryID { get; set; }
      public virtual Country FromCountry { get; set; }
      public Int32 ToCityID { get; set; }
      public virtual City ToCity { get; set; }
      public Int32 ToCountryID { get; set; }
      public virtual Country ToCountry { get; set; }
  }
  </code></pre>
  
  <blockquote>
    <p>TransportOfferDto:</p>
  </blockquote>
  
  <pre><code>[MapsTo(typeof(TransportOffer))]
  [MapsFrom(typeof(TransportOffer))]
  public class TransportOfferDto : EntityDto&lt;Guid&gt;
  {
      public Guid TransportToken { get; set; }
      public DateTime Date { get; set; }    
      public Int32 FromCityID { get; set; }
      public virtual CityDto FromCity { get; set; }       
      public Int32 FromCountryID { get; set; }
      public virtual CountryDto FromCountry { get; set; } 
      public Int32 ToCityID { get; set; }
      public virtual CityDto ToCity { get; set; }
      public Int32 ToCountryID { get; set; }
      public virtual Country ToCountry { get; set; }
  } 
  </code></pre>
  
  <blockquote>
    <p>Query</p>
  </blockquote>
  
  <pre><code>var query = Repository.GetAll()
              .Include(x =&gt; x.FromCountry)
              .Include(x =&gt; x.FromCity)
              .Include(x =&gt; x.ToCountry)
              .Include(x =&gt; x.ToCity)
              .Where(p =&gt; p.MembershipID == input).ToList();
  
  return ObjectMapper.Map&lt;List&lt;TransportOfferDto&gt;&gt;(query);
  </code></pre>