[英]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.