When executing the below code: The block of code being executed is with the stars
public static class DbContextExtensions { public static async Task<List> SqlQueryAsync(this DbContext db, string sql, object[] parameters = null, CancellationToken cancellationToken = default) where T : class { if (parameters is null) { parameters = 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;
}
}
}
I'm getting the following error:
System.InvalidOperationException: The type 'System.Threading.ExecutionContext&' of property 'Context' on type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1[System.Collections.Generic.List`1[SpiritWMSApiCore2.Models.Unitech_ASNInfo_BOLResult],SpiritWMSApiCore2.Models.SIRISContextProcedures+<Unitech_ASNInfo_BOLAsync>d__56]' is invalid for serialization or deserialization because it is a pointer type, is a ref struct, or contains generic parameters that have not been replaced by specific types.
I looked up with bing chat gpt and gives the following, but i still don't know how to resolve it...
System.InvalidOperationException: The type 'System.Threading.ExecutionContext&' of property 'Context' on type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1[System.Collections.Generic.List`1[SpiritWMSApiCore2.Models.Unitech_ASNInfo_BOLResult],SpiritWMSApiCore2.Models.SIRISContextProcedures+<Unitech_ASNInfo_BOLAsync>d__56]' is invalid for serialization or deserialization because it is a pointer type, is a ref struct, or contains generic parameters that have not been replaced by specific types.
For me, this was a missing
awaiti.e. I was trying to serialise aTask<something>rather than asomething. Serialising an uncompleted Task is obviously impossible