'AutoMapper Exception in inner entities

I have Entities and Dtos like below

public abstract class ProductEntity : BaseEntity {
    public string? Title { get; set; }
    public string? Subtitle { get; set; }

    public IEnumerable<BrandEntity>? Brands { get; set; }
}

public class ProductReadDto {
    public string? Title { get; set; }
    public string? Subtitle { get; set; }
    public IEnumerable<IdTitleReadDto>? Brands { get; set; }
}

public class ProductCreateUpdateDto {
    public string? Title { get; set; }
    public string? Subtitle { get; set; }
    public IEnumerable<Guid>? Brands { get; set; }
}


public class BrandEntity : BaseEntity {
    public string Title { get; set; }
    public string? Subtitle { get; set; }
    public IEnumerable<ProductEntity>? Product { get; set; }
}

public class BrandReadDto {
    public string? Title { get; set; }
    public string? Subtitle { get; set; }
}

public class BrandCreateUpdateDto {
    public string? Title { get; set; }
    public string? Subtitle { get; set; }
}

public class AutoMapperProfile : Profile {
    public AutoMapperProfile() {
        CreateMap<BrandEntity, IdTitleReadDto>().ReverseMap();
        CreateMap<BrandEntity, IdTitleCreateUpdateDto>().ReverseMap();

        CreateMap<ProductEntity, ProductReadDto>().ReverseMap();
        CreateMap<ProductEntity, ProductCreateUpdateDto>().ReverseMap();
    }
}

I get error on creating product when I pass brands

AutoMapper.AutoMapperMappingException: Error mapping types.

Mapping types:
ProductCreateUpdateDto -> ProductEntity
Utilities_aspnet.Product.ProductCreateUpdateDto -> Utilities_aspnet.Product.ProductEntity

Type Map configuration:
ProductCreateUpdateDto -> ProductEntity
Utilities_aspnet.Product.ProductCreateUpdateDto -> Utilities_aspnet.Product.ProductEntity

Destination Member:
Reference

 ---> AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.

Mapping types:
Guid -> ReferenceEntity
System.Guid -> Utilities_aspnet.IdTitle.ReferenceEntity
   at lambda_method1810(Closure , Guid , ReferenceEntity , ResolutionContext )
   at lambda_method1809(Closure , Object , ProductEntity , ResolutionContext )
   --- End of inner exception stack trace ---
   at lambda_method1809(Closure , Object , ProductEntity , ResolutionContext )


Solution 1:[1]

You're mapping to ProjectEntity; but ProjectEntity is not withing these clases you've shared. Maybe you're trying to map to ProductEntity

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jgondev