'Why Automapper returns null while mapping List<T> in aspnet.core 3.1?

In my .net core 3.1 I would like to show nested elements using automapper.

In my dto I have field:

    public class ServerChartDto
    {
       .. other values
        public DiskSizeInfo DiskSize { get; set; }
    }

    public class DiskSizeInfo
    {
        public List<object> Projects { get; set; }
        public long Total { get; set; }
    }

My mapper looks like:

CreateMap<Organization, ServerChartDto>()
   ...other mappings
 .ForMember(d => d.DiskSize, o => o.MapFrom(s => s.Projects
                    .Select(y => new DiskSizeInfo
                    {
                        Projects =
                        {
                            new
                            {
                                Name = y.Name,
                                Used = y.Servers.Sum(z => z.DiskSize)
                            }
                        },
                        Total = y.Servers.Sum(z => z.DiskSize)
                    }).ToList()))

Want result something like:

diskSize: {
    projects: [
      {
        name: 'fewregrge'
        used: 234
      }
    ],
    total: 2342
  }


Sources

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

Source: Stack Overflow

Solution Source