diff --git a/LiteDB/Client/Mapper/BsonMapper.cs b/LiteDB/Client/Mapper/BsonMapper.cs index c613e7bc3..d4fe83777 100644 --- a/LiteDB/Client/Mapper/BsonMapper.cs +++ b/LiteDB/Client/Mapper/BsonMapper.cs @@ -235,16 +235,14 @@ internal EntityMapper GetEntityMapper(Type type) { //TODO: needs check if Type if BsonDocument? Returns empty EntityMapper? - if (!_entities.TryGetValue(type, out EntityMapper mapper)) + lock (_entities) { - lock (_entities) + if (!_entities.TryGetValue(type, out EntityMapper mapper)) { - if (!_entities.TryGetValue(type, out mapper)) - return this.BuildAddEntityMapper(type); + return this.BuildAddEntityMapper(type); } + return mapper; } - - return mapper; } ///