Skip to content

Derived interfaces are no longer mapped in 11.0.1 #3886

@jobwttraining

Description

@jobwttraining

Source/destination types

// Put your source/destination types here
public class Source
{
	public string PropertyA {get; set;}
	public string PropertyB {get; set;}
	public string Name {get; set;}	
}

public class Target : IProperties
{
	public string PropertyA { get; set; }
	public string PropertyB { get; set; }
	public string Name {get; set;}	
}

public interface IProperties : IPropertyA, IPropertyB
{
	string Name {get; set;}	
}

public interface IPropertyA
{
	string PropertyA {get; set;}
}

public interface IPropertyB
{
	string PropertyB {get; set;}
}

Mapping configuration

// Mapper.Initialize or just the CreateMap snippet 
public class MyProfile : Profile
{
	public MyProfile()
	{
		CreateMap<Source, IProperties>()
			.IncludeBase<Source, IPropertyA>()
			.IncludeBase<Source, IPropertyB>()
			;

		CreateMap<Source, IPropertyA>()
		;

		CreateMap<Source, IPropertyB>()
		;
	}
}

Version: 11.0.1

Expected behavior

I expect all properties of the target object to be mapped. This was still the case with version 11.0.0

Actual behavior

Only PropertyB is mapped, Name and PropertyA are null

Steps to reproduce

// Your calls to Mapper.Map or ProjectTo here, with source/destination objects constructed

	MapperConfiguration mapperConfiguration = new MapperConfiguration(cfg =>
	{
		cfg.AddProfile<MyProfile>();
	});

	IMapper mapper = new Mapper(mapperConfiguration);

	Source source = new Source
	{
		Name = "Name",
		PropertyA = "PropertyA",
		PropertyB = "PropertyB"
	};

	Target target = new Target();

	mapper.Map(source, target);

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