I'm trying to map a NetTopologySuite.Geometries.MultiPoint with Automapper but I keep getting the error System.ArgumentException: NetTopologySuite.Geometries.MultiPoint needs to have a constructor with 0 args or only optional args
.
var config = new MapperConfiguration(cfg => {});
var mapper = config.CreateMapper();
MultiPoint mp1 = null;
MultiPoint mp2 = mapper.Map<MultiPoint>(mp1); // throws
Indeed, this type doesn't have a constructor with 0 arguments. I've tried specifying how to instantiate the type:
new MapperConfiguration(cfg => {
cfg.CreateMap<MultiPoint, MultiPoint>()
.ConstructUsing(mp => new MultiPoint((Point[])mp.Geometries));
});
Same error. To reproduce with a simpler code, I created a class with no 0 args constructor.
var config = new MapperConfiguration(cfg => { });
var mapper = config.CreateMapper();
TestCollection tc1 = null;
TestCollection tc2 = mapper.Map<TestCollection>(tc1); // throws
class Test
{
}
class TestCollection : IEnumerable<Test>
{
public TestCollection(Test[] tests) => Tests = tests;
public Test[] Tests { get; set; }
public IEnumerator<Test> GetEnumerator() => new TestCollectionEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
class TestCollectionEnumerator : IEnumerator<Test>
{
object IEnumerator.Current => Current;
public Test Current { get; }
public bool MoveNext() => false;
public void Reset() { }
public void Dispose() { }
}
Is it a bug or am I missing something?