简体   繁体   English

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

[英]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.我正在关注 .NET 6 上的一个简单教程,它应该非常简单,但显然我遇到了异常。 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 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;
        
    }

RpgClass is Rpg类是

[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.异常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. is thrown right at var dbCharacters = await _context.Characters.ToListAsync();被扔在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.如果我同步调用它_context.Characters.ToList()它工作正常,但不能让它异步工作。

I have both .NET 5 SDK and .NET 6 SDK installed, if that could be a potential issue.我同时安装了 .NET 5 SDK 和 .NET 6 SDK,如果这可能是一个潜在的问题。

Much appreciated for your helpful responses.非常感谢您提供有用的回复。

I was missing an await in the controller where I was calling the GetAllCharacters() method.我在调用GetAllCharacters()方法的 controller 中缺少等待。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.NotSupportedException:不支持“System.DateOnly”实例的序列化和反序列化 - System.NotSupportedException: Serialization and deserialization of 'System.DateOnly' instances are not supported System.NotSupportedException : &#39;不支持给定路径的格式。&#39; C# - System.NotSupportedException : 'The format of the given path is not supported.' C# System.NotSupportedException: '不支持指定的路径格式。' - System.NotSupportedException: 'The specified path format is not supported.' System.NotSupportedException:“不支持给定路径的格式。” - System.NotSupportedException: 'The given path's format is not supported.' System.NotSupportedException:&#39;不支持在基于任务的异步方法上使用&#39;System.Threading.CancellationToken&#39;。&#39; - System.NotSupportedException: 'The use of 'System.Threading.CancellationToken' on the task-based asynchronous method is not supported.' System.NotSupportedException:“不支持返回 System.IServiceProvider 的配置服务。” 带结构 Map - System.NotSupportedException: 'ConfigureServices returning an System.IServiceProvider isn't supported.' with Structure Map 错误System.NotSupportedException:不支持给定路径的格式 - Error System.NotSupportedException : The given path's format is not supported system.notsupportedexception不支持给定路径的格式 - system.notsupportedexception the given path's format is not supported C# JSON 反序列化 System.NotSupportedException - C# JSON Deserialization System.NotSupportedException > 'System.Action' 的序列化和反序列化 ASP.NET - Serialization and deserialization of > 'System.Action' ASP.NET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM