This project has moved. For the latest updates, please go here.


Strange behavior when mapping inner collection


i'm getting a strange behavior when mapping inner collection. What happens is that the inner property isn't correctly filled. But if I map the inner property I get the mapping done. As shown in the sample bellow, the call to the map the collection to the _to variable works, but when I map the _message variable, the _message.To has 0 items.
Any thoughts why?
Mapper.CreateMap<MailMessage, System.Net.Mail.MailMessage>();
Mapper.CreateMap<MailAddress, System.Net.Mail.MailAddress>()
.ConstructUsing(x => new System.Net.Mail.MailAddress(x.Address));
Mapper.CreateMap<MailAddressCollection, System.Net.Mail.MailAddressCollection>()
.ConvertUsing(new MailAddressCollectionConverter());
Mapper.AssertConfigurationIsValid(); // ALL OK :)
public void Send(MailMessage message)
var _to = Mapper.Map<MailAddressCollection, System.Net.Mail.MailAddressCollection>(message.To); // OK _To.Count = 1 has expected
System.Net.Mail.MailMessage _message = Mapper.Map<MailMessage, System.Net.Mail.MailMessage>(message); // NOT OK _message.To.Count = 0 :(
internal class MailAddressCollectionConverter : ITypeConverter<MailAddressCollection, System.Net.Mail.MailAddressCollection>
    #region ITypeConverter<MailAddressCollection,MailAddressCollection> Members
    public System.Net.Mail.MailAddressCollection Convert(ResolutionContext context)
        var col = new System.Net.Mail.MailAddressCollection();
        if (!context.IsSourceValueNull)
            var source = context.SourceValue as MailAddressCollection;
            if (source != null)
                foreach (var to in source)
        return col;
Closed Sep 2, 2011 at 10:46 PM by jbogard
All issues moved to GitHub


icnocop wrote Jul 29, 2011 at 7:00 PM

Can you show us your custom MailMessage class?

wrote Sep 2, 2011 at 10:46 PM

wrote Feb 22, 2013 at 12:49 AM

wrote May 16, 2013 at 11:59 AM