System.NotSupportedException:不支持“System.Action”实例的序列化和反序列化。路径:$.MoveNextAction

vpp*_*090 19 c# asp.net-core asp.net-core-webapi .net-6.0

我正在遵循有关 .NET 6 的简单教程,它应该工作起来非常简单,但显然我遇到了异常。示例代码如下:

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;
}
Run Code Online (Sandbox Code Playgroud)

GetCharacterDto中的代码是:

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;
}

Run Code Online (Sandbox Code Playgroud)

角色扮演类:

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

例外情况

System.NotSupportedException:不支持“System.Action”实例的序列化和反序列化。路径:$.MoveNextAction。被扔到正确的位置

var dbCharacters = await _context.Characters.ToListAsync(); 
Run Code Online (Sandbox Code Playgroud)

如果我同步调用它

_context.Characters.ToList();
Run Code Online (Sandbox Code Playgroud)

它工作正常,但无法让它异步工作。

我安装了 .NET 5 SDK 和 .NET 6 SDK(如果这可能是一个潜在问题)。

vpp*_*090 66

await我在调用异步方法的控制器中缺少一个GetAllCharacters()