-
Notifications
You must be signed in to change notification settings - Fork 85
Description
Encountering a serialization exception when executing an asynchronous aggregation query using GroupBy and CountGroupMembers, followed by ToArrayAsync() or ToListAsync(). The exception suggests that the serialization process is attempting to handle an unsupported type, leading to a failure.
Steps to Reproduce:
Define the Data Model:
using Redis.OM.Modeling;
[Document(StorageType = StorageType.Json)]
public class Car
{
[RedisIdField]
public string Id { get; set; }
[Indexed]
public string Mk { get; set; } // Make
[Indexed]
public string Md { get; set; } // Model
// Additional properties...
}Set Up the Aggregation Query:
var provider = new RedisConnectionProvider("redis://localhost:6379");
var aggregationSet = provider.AggregationSet<Car>();
var filteredAggregations = aggregationSet
.GroupBy(x => new { x.Mk, x.Md })
.CountGroupMembers();Execute the Query Asynchronously:
var results = await filteredAggregations.ToArrayAsync();
Observed Behavior: Executing the above code results in the following exception:
System.InvalidOperationException: The type 'System.Threading.ExecutionContext&' of property 'Context' on type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1[Namespace.ClassName,System.Runtime.CompilerServices.IAsyncStateMachine]' 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.
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_CannotSerializeInvalidType(Type typeToConvert, Type declaringType, MemberInfo memberInfo)
at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreatePropertyInfo(JsonTypeInfo typeInfo, Type typeToConvert, MemberInfo memberInfo, JsonSerializerOptions options, Boolean shouldCheckForRequiredKeyword, Boolean hasJsonIncludeAttribute)
at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.AddMembersDeclaredBySuperType(JsonTypeInfo typeInfo, Type currentType, Boolean constructorHasSetsRequiredMembersAttribute, PropertyHierarchyResolutionState& state)
at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.PopulateProperties(JsonTypeInfo typeInfo)
at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateTypeInfoCore(Type type, JsonConverter converter, JsonSerializerOptions options)
at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type type, JsonSerializerOptions options)
at System.Text.Json.JsonSerializerOptions.GetTypeInfoNoCaching(Type type)
at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context)
--- End of stack trace from previous location ---