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.
results = GetAllCharacters(); return results;
it would work with sync but will have this symptomps for async – Ruble