© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
32 replies
ruskan

Empty DTO list from swagger

For some reason whatever list of sizes I input, it always tells me in the debugger that the list of ProductCreateSizeRequests is empty.
public class CreateProductRequest
{
    public string Name { get; set; }
    public double Price { get; set; }
    public string Category { get; set; }
    public string Subcategory { get; set; }
    public string Color { get; set; }
    public int? ThumbnailIndex { get; set; }
    public List<ProductCreateSizeRequest> Sizes { get; set; }
    public List<IFormFile> Images { get; set; }
}
public class CreateProductRequest
{
    public string Name { get; set; }
    public double Price { get; set; }
    public string Category { get; set; }
    public string Subcategory { get; set; }
    public string Color { get; set; }
    public int? ThumbnailIndex { get; set; }
    public List<ProductCreateSizeRequest> Sizes { get; set; }
    public List<IFormFile> Images { get; set; }
}

public override async Task<ActionResult<Product>> CreateProduct(CreateProductRequest request)
    {
        _logger.LogInformation("POST Rest Request: Create product.");

        try
        {
            Product product = await _productCommandService.CreateProduct(request);
            
            foreach (IFormFile imageFile in request.Images)
            {
                string? response = await CreateImageForProductCreation(product.Id, imageFile);

                if (response != null)
                {
                    _logger.LogInformation($"Image Creation Response: " + response);
                }
            }

            foreach (ProductCreateSizeRequest size in request.Sizes)
            {
                _logger.LogInformation("AICI E PROBLEMA");
                string? response = await CreateSizeForProductCreation(product.Id, size);
                
                if (response != null)
                {
                    _logger.LogInformation($"Size Creation Response: " + response);
                }
            }

            return Created(GenerateUriForProduct(product.Id), product);
        }
        catch (InvalidValue exception)
        {
            _logger.LogInformation("400 Rest Response: " + exception.Message);
            return BadRequest(exception.Message);
        }
    }
public override async Task<ActionResult<Product>> CreateProduct(CreateProductRequest request)
    {
        _logger.LogInformation("POST Rest Request: Create product.");

        try
        {
            Product product = await _productCommandService.CreateProduct(request);
            
            foreach (IFormFile imageFile in request.Images)
            {
                string? response = await CreateImageForProductCreation(product.Id, imageFile);

                if (response != null)
                {
                    _logger.LogInformation($"Image Creation Response: " + response);
                }
            }

            foreach (ProductCreateSizeRequest size in request.Sizes)
            {
                _logger.LogInformation("AICI E PROBLEMA");
                string? response = await CreateSizeForProductCreation(product.Id, size);
                
                if (response != null)
                {
                    _logger.LogInformation($"Size Creation Response: " + response);
                }
            }

            return Created(GenerateUriForProduct(product.Id), product);
        }
        catch (InvalidValue exception)
        {
            _logger.LogInformation("400 Rest Response: " + exception.Message);
            return BadRequest(exception.Message);
        }
    }
,
image.png
image.png
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Converting from DTO to DomainModel
C#CC# / help
2y ago
❔ Get id from query or DTO
C#CC# / help
4y ago
❔ FluentValidation DTO
C#CC# / help
3y ago
DTO is fine? DTO have any alternatives?
C#CC# / help
2y ago