Skip to content

Commit 350adc8

Browse files
committed
CSHARP-1879: Freeze base class map when derived class map is frozen.
1 parent d02772d commit 350adc8

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/MongoDB.Bson/Serialization/BsonClassMap.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ public BsonClassMap Freeze()
481481
{
482482
_baseClassMap = LookupClassMap(baseType);
483483
}
484+
_baseClassMap.Freeze();
484485
_discriminatorIsRequired |= _baseClassMap._discriminatorIsRequired;
485486
_hasRootClass |= (_isRootClass || _baseClassMap.HasRootClass);
486487
_allMemberMaps.AddRange(_baseClassMap.AllMemberMaps);

src/MongoDB.Bson/Serialization/Serializers/BsonClassMapSerializer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public BsonClassMapSerializer(BsonClassMap classMap)
4848
var message = string.Format("Must be a BsonClassMap for the type {0}.", typeof(TClass));
4949
throw new ArgumentException(message, "classMap");
5050
}
51+
if (!classMap.IsFrozen)
52+
{
53+
throw new ArgumentException("Class map is not frozen.", nameof(classMap));
54+
}
5155

5256
_classMap = classMap;
5357
}

0 commit comments

Comments
 (0)