When I upgraded to Automapper 5.1.1, mapping of collections that are defined with readonly properties stopped to work (this works perfectly fine using Automapper 4.2.1)
Here is a sample code that you can try using both versions of Automapper to verify the behavior change. With automapper 5.1.1 result.MyList has zero elements.
class TestAutomapper
{
public static void Test()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<Test, TestDto>();
});
var test = new Test();
test.MyList.Add(1);
var result= Mapper.Map<TestDto>(test);
}
}
public class Test
{
public List<int> MyList { get; } = new List<int>();
}
public class TestDto
{
public List<int> MyList { get; } = new List<int>();
}
How can I get the map to work correctly using Automapper 5.1.1?