using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using MongoDB.Bson; using MongoDB.Bson.Serialization; namespace TestLookupClassMapDeadlock { public class C { public ObjectId Id; } public class X { public ObjectId Id; } public static class Program { public static void Main(string[] args) { var thread1 = new Thread(Start1); var thread2 = new Thread(Start2); thread1.Start(); Thread.Sleep(TimeSpan.FromSeconds(0.5)); thread2.Start(); Thread.Sleep(TimeSpan.FromSeconds(0.5)); Console.WriteLine("Waiting for threads to finish"); thread1.Join(); thread2.Join(); Console.WriteLine("Threads finished"); Console.WriteLine("Press Enter to continue"); Console.ReadLine(); } public static void Start1() { Console.WriteLine("Thread1: calling BsonDefaultSerializer.LookupActualType"); BsonDefaultSerializer.RegisterDiscriminator(typeof(X), "X"); var type = BsonDefaultSerializer.LookupActualType(typeof(object), "X"); Console.WriteLine("Thread1: returned"); } public static void Start2() { Console.WriteLine("Thread2: calling BsonClassMap.LookupClassMap"); var classMap = BsonClassMap.LookupClassMap(typeof(C)); Console.WriteLine("Thread2: returned"); } } }