Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.NotSupportedException: Serialization and deserialization of 'System.Action' instances are not supported. Path: $.MoveNextAction

I am following a simple tutorial on .NET 6 and it should work really simple, but apparently I get the exception. The sample code is the following:

public async Task<ServiceResponse<List<GetCharacterDto>>> GetAllCharacters()
{
    var response = new ServiceResponse<List<GetCharacterDto>>();
    var dbCharacters = await _context.Characters.ToListAsync();
    response.Data = dbCharacters.Select(c => _mapper.Map<GetCharacterDto>(c)).ToList();

    return response;
}

The code in GetCharacterDto is:

public class GetCharacterDto
{ 
    public int Id { get; set; }
    
    public string Name { get; set; } = "Frodo";

    public int HitPoints { get; set; } = 100;

    public int Strength { get; set; } = 10;

    public int Defense { get; set; } = 10;

    public int Intelligence { get; set; } = 10;

    public RpgClass Class { get; set; } = RpgClass.Knight;
}

RpgClass:

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum RpgClass
{
    Knight = 1,
    Mage = 2,
    Cleric = 3
}

The exception

System.NotSupportedException: Serialization and deserialization of 'System.Action' instances are not supported. Path: $.MoveNextAction. Is thrown right at

var dbCharacters = await _context.Characters.ToListAsync(); 

If I call it synchronously

_context.Characters.ToList();

it works alright, but can't get it to work asynchronously.

I have both .NET 5 SDK and .NET 6 SDK installed, if that could be a potential issue.

like image 545
vpp090 Avatar asked Sep 09 '25 16:09

vpp090


2 Answers

I was missing an await in the controller where I was calling the asynchronous GetAllCharacters() method.

like image 109
vpp090 Avatar answered Sep 12 '25 06:09

vpp090


[HttpGet("Info")]
[Authorize]
public async Task<ActionResult<UserDto>> GetCurrentUserInfo()
{
    var user = await _userService.GetCurrentUserInfo();
    return user.ToDto();
}

please remove ok and return directly

like image 20
Manjeet Singh Avatar answered Sep 12 '25 04:09

Manjeet Singh