AutoMapper / AutoMapper.Collection

AutoMapper support for updating existing collections by equivalency
MIT License
245 stars 59 forks source link

`StackOverflowException` when invoking `AddCollectionMappers()` twice. #187

Closed prochnowc closed 2 months ago

prochnowc commented 2 months ago

When invoking AddCollectionMappers() twice all collection mapping operations throw a StackoverflowException.

public class UnitTest1
{
    public class DTO { }

    public class Model { }

    [Fact]
    public void Test1()
    {
        var config = new MapperConfiguration(c =>
        {
            c.AddCollectionMappers();
            c.AddCollectionMappers();
            c.CreateMap<Model, DTO>();
        });

        var mapper = new Mapper(config);
        mapper.Map<ICollection<DTO>>(new List<Model>() { new Model() });
    }
}

It would be really nice ifAddCollectionMappers() checks if the mapper is already registered. This is extremely useful when the application has many independent invocations of services.AddAutoMapper() in completely independent modules.

lbargaoanu commented 2 months ago

This project doesn't have a maintainer.

prochnowc commented 1 month ago

@lbargaoanu Can I open a PR to fix this problem?

lbargaoanu commented 1 month ago

No, there's nobody to review it.