Hello!
I am using ASP .NET Core 6 and MongoDB.Driver 2.21.0 I need a model that has a dynamic or generic property.
The property in question is declared as follows:
public dynamic data { get; set; }
After creating, the services and the controller, when I try to create using swagger in mongoDB I get this error:
MongoDB.Bson.BsonSerializationException: An error occurred while serializing the data property of class prueba.Models.Servicio.Servicio: Type System.Text.Json.JsonElement is not configured as a type that is allowed to be serialized for this instance of ObjectSerializer.
---> MongoDB.Bson.BsonSerializationException: Type System.Text.Json.JsonElement is not configured as a type that is allowed to be serialized for this instance of ObjectSerializer.
at MongoDB.Bson.Serialization.Serializers.ObjectSerializer.SerializeDiscriminatedValue(BsonSerializationContext context, BsonSerializationArgs args, Object value, Type actualType)
at MongoDB.Bson.Serialization.Serializers.ObjectSerializer.Serialize(BsonSerializationContext context, BsonSerializationArgs args, Object value)
at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Serialize(IBsonSerializer serializer, BsonSerializationContext context, Object value)
at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.SerializeMember(BsonSerializationContext context, Object obj, BsonMemberMap memberMap)
I have been investigating and I have not found any solution, Could you tell me how to solve it?
Thanks in advance.