Skip to content

AllowNullCollections=false not honored for ICollection #2145

@tboby

Description

@tboby

Source/destination types

    public class Foo
    {
        public List<int> fooList = null;
    }

    public class FooDB
    {
        public ICollection<int> fooList = null;
    }

Mapping configuration

   public class ExplicitGlobalDefaultProfile : Profile
    {
        public ExplicitGlobalDefaultProfile()
        {
            AllowNullCollections = false;
            AllowNullDestinationValues = true;
            CreateMap<Foo, FooDB>();
        }
    }

    public class ImplicitGlobalDefaultProfile : Profile {
        public ImplicitGlobalDefaultProfile()
        {
            CreateMap<Foo, FooDB>();
        }
    }

Version: x.y.z

6.1.0

Expected behavior

I expect fooDB.fooList to be an empty collection of some kind.
In 6.0.2 (and 5.2.0) this is the actual behaviour.

Actual behavior

fooList is null.

Steps to reproduce

        var explicitGlobalConfig = new MapperConfiguration(cfg => { cfg.AddProfile<ExplicitGlobalDefaultProfile>(); });
        var implicitGlobalConfig = new MapperConfiguration(cfg => { cfg.AddProfile<ImplicitGlobalDefaultProfile>(); });
        var explicitMapper = explicitGlobalConfig.CreateMapper();
        var implicitMapper = implicitGlobalConfig.CreateMapper();
        var foo = new Foo();
        var explicitFooDB = explicitMapper.Map<Foo, FooDB>(foo);
        var implicitFooDB = implicitMapper.Map<Foo, FooDB>(foo);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions