Hey Jimmy - A second issue I am hitting during upgrade to 5.0.
Unable to create instance of class AutoMapperTest.UnitTest1. Error: System.ArgumentException: Argument types do not match.
at System.Linq.Expressions.Expression.Condition(Expression test, Expression ifTrue, Expression ifFalse)
at AutoMapper.Mappers.ArrayMapper.MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider, PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression)
at AutoMapper.Execution.TypeMapPlanBuilder.CreatePropertyMapFunc(PropertyMap propertyMap, IConfigurationProvider configurationProvider, TypeMapRegistry typeMapRegistry, ParameterExpression srcParam, ParameterExpression destParam, ParameterExpression ctxtParam)
at AutoMapper.Execution.TypeMapPlanBuilder.TryPropertyMap(PropertyMap pm, IConfigurationProvider configurationProvider, TypeMapRegistry registry, ParameterExpression srcParam, ParameterExpression destParam, ParameterExpression ctxtParam)
at AutoMapper.Execution.TypeMapPlanBuilder.<>c__DisplayClass5_0.<CreateAssignmentFunc>b__1(PropertyMap pm)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at AutoMapper.Execution.TypeMapPlanBuilder.CreateAssignmentFunc(TypeMap typeMap, IConfigurationProvider configurationProvider, TypeMapRegistry registry, ParameterExpression srcParam, ParameterExpression destParam, ParameterExpression ctxtParam, Expression destinationFunc)
at AutoMapper.Execution.TypeMapPlanBuilder.BuildMapperFunc(TypeMap typeMap, IConfigurationProvider configurationProvider, TypeMapRegistry
when using these mappings:
[TestClass]
public class UnitTest1
{
static UnitTest1()
{
Mapper.Initialize(cfg =>
{
cfg.AllowNullCollections = true; // removing this makes it work; unfortunately, I can't turn it off
cfg.CreateMap<Source, Target>();
cfg.CreateMap<SourceItem, TargetItem>();
});
}
[TestMethod]
public void IncludedMappings()
{
var src = new Source
{
X = 5,
Items = new List<SourceItem>
{
new SourceItem { I = 1 },
new SourceItem { I = 2 },
new SourceItem { I = 3 }
}
};
var dest = Mapper.Map<Source, Target>(src);
Assert.AreEqual(src.X, dest.X);
Assert.AreEqual(3, dest.Items.Length);
Assert.AreEqual(1, dest.Items[0].I);
Assert.AreEqual(2, dest.Items[1].I);
Assert.AreEqual(3, dest.Items[2].I);
}
}
class Source
{
public int X { get; set; }
public IEnumerable<SourceItem> Items { get; set; }
}
class SourceItem
{
public int I { get; set; }
}
class Target
{
public int X { get; set; }
public TargetItem[] Items { get; set; }
}
class TargetItem
{
public int I { get; set; }
}
From what I see, it looks like this worked from 3.3 all the way through the 4.2.1 release, but no longer works in 5.0.
Thanks again!
Chris Bristol