MySql.Data.MySqlClient.MySqlProtocolException:“Packet received out-of-order. Expected 1; got 2.”

环境为:

dotnet core 3.1 webapi efcore

maridb 10

Pomelo.EntityFrameworkCore.MySql

解决方案:

await _context.SaveChangesAsync();

异步操作要加await,不然会出现此异常。

参考:https://github.com/mysql-net/MySqlConnector/issues/496

It is not permitted to have multiple in-flight async operations on the same connection at the same time; you do have to await any existing operation before starting a new one.
However, you should also get a more helpful exception message (better than Packet received out-of-order) that helps you understand the problem and fix it. So if you are able to get a repro or a code sample that shows the problem, that would be good as it could help me identify where there is a missing check (for this invalid behaviour) in the code.
不允许同时在同一连接上进行多个进行中异步操作;您必须await任何现有的异步操作然后再开始一个新的操作。
但是,您还应该获得一条更有用的异常消息(比Packet received out-of-order这有助于你理解并解决问题。因此,如果您能够获得显示问题的repro或代码示例,那将是很好的,因为它可以帮助我识别代码中缺少检查(这种无效行为)的位置。

posted on 2020-01-06 16:54  VincentZhu  阅读(1185)  评论(0编辑  收藏  举报