From 51b206766f41ba06f4ea75547d898d221504adf2 Mon Sep 17 00:00:00 2001 From: Mirko Da Corte Date: Fri, 12 Aug 2022 19:09:28 +0200 Subject: [PATCH] fix issue --- .../Serializers/ReferenceSerializer.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/MongODM.Core/Serialization/Serializers/ReferenceSerializer.cs b/src/MongODM.Core/Serialization/Serializers/ReferenceSerializer.cs index b09dc86b..237f2f1c 100644 --- a/src/MongODM.Core/Serialization/Serializers/ReferenceSerializer.cs +++ b/src/MongODM.Core/Serialization/Serializers/ReferenceSerializer.cs @@ -318,17 +318,21 @@ public void SetDocumentId(object document, object id) public bool TryGetMemberSerializationInfo(string memberName, out BsonSerializationInfo serializationInfo) { - var modelType = configuration.Schemas.Values + serializationInfo = default!; + + var classMap = configuration.Schemas.Values .Select(s => s.ActiveMap.BsonClassMap) .Where(cm => cm.GetMemberMap(memberName) != null) - .First() - .ClassType; - var serializer = configuration.Schemas[modelType].ActiveBsonClassMapSerializer; + .FirstOrDefault(); + + if (classMap is null) + return false; + var serializer = configuration.Schemas[classMap.ClassType].ActiveBsonClassMapSerializer; if (serializer is IBsonDocumentSerializer documentSerializer) return documentSerializer.TryGetMemberSerializationInfo(memberName, out serializationInfo); else - throw new InvalidOperationException("Can't find a valid serializer"); + return false; } // Helpers.