簡體   English   中英

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

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

我正在關注 .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;
        }

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

Rpg類是

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

異常System.NotSupportedException: Serialization and deserialization of 'System.Action' instances are not supported. Path: $.MoveNextAction. System.NotSupportedException: Serialization and deserialization of 'System.Action' instances are not supported. Path: $.MoveNextAction. 被扔在var dbCharacters = await _context.Characters.ToListAsync();

如果我同步調用它_context.Characters.ToList()它工作正常,但不能讓它異步工作。

我同時安裝了 .NET 5 SDK 和 .NET 6 SDK,如果這可能是一個潛在的問題。

非常感謝您提供有用的回復。

我在調用GetAllCharacters()方法的 controller 中缺少等待。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM