提问人:sagesky36 提问时间:11/17/2023 最后编辑:sagesky36 更新时间:11/17/2023 访问量:15
使用 EF Power Tools 进行序列化的 InvalidOperationEception
InvalidOperationEception with serialization with EF Power Tools
问:
执行以下代码时: 正在执行的代码块带有星号
公共静态类 DbContextExtensions { public static async Task<List> SqlQueryAsync(this DbContext db, string sql, object[] parameters = null, CancellationToken cancellationToken = default) 其中 T : 类 { if(参数为 null) { 参数 = new object[] { }; }
**if (typeof(T).GetProperties().Any())
{
return await db.Set<T>().FromSqlRaw(sql, parameters).ToListAsync(cancellationToken);
}**
else
{
await db.Database.ExecuteSqlRawAsync(sql, parameters, cancellationToken);
return default;
}
}
}
我收到以下错误:
System.InvalidOperationException:类型“System.Runtime.CompilerServices.AsyncTaskMethodBuilder1[System.Collections.Generic.List'1[SpiritWMSApiCore2.Models.Unitech_ASNInfo_BOLResult],SpiritWMSApiCore2.Models.SIRISContextProcedures+<Unitech_ASNInfo_BOLAsync>d__56]”上的属性“Context”的类型“System.Threading.ExecutionContext”对于序列化或反序列化无效,因为它是指针类型、引用结构或包含具有未被特定类型取代。1+AsyncStateMachineBox
我用 bing chat gpt 查找并给出了以下内容,但我仍然不知道如何解决它......
System.InvalidOperationException:类型“System.Runtime.CompilerServices.AsyncTaskMethodBuilder1[System.Collections.Generic.List'1[SpiritWMSApiCore2.Models.Unitech_ASNInfo_BOLResult],SpiritWMSApiCore2.Models.SIRISContextProcedures+<Unitech_ASNInfo_BOLAsync>d__56]”上的属性“Context”的类型“System.Threading.ExecutionContext”对于序列化或反序列化无效,因为它是指针类型、引用结构或包含具有未被特定类型取代。1+AsyncStateMachineBox
答: 暂无答案
评论
System.InvalidOperationException: The type 'System.Threading.ExecutionContext&' of property 'Context' on type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder
1[System.Collections.Generic.List
System.Threading.ExecutionContext&