I cheated - ReSharper actually breaks that line into a couple of line automatically, making it easier to read :)
Ok so, I have verified that the approach you suggested works. Thank you for that :)
I also discovered why I randomly encountered exceptions in the past.
As I mentioned, I have 20 - 25 classes that inherit from my base class. This is actually akin to a queue with several different classes that are queue items. I push them into the queue as MongoDB doc's and then pop them off the queue and send them to the correct processor based on the the class type.
I observed that the queue processor was throwing exceptions randomly. After experimenting tonight based on this discussion and browsing through the source, I realized that when a class is converted to a document, a BsonClassMap is created for that class, if it does not already exist.
Originally, I was not informing my app in any way (such as attributes or method calls) about my derived classes - but it was working, sometimes. As it turns out, it worked sometimes because I was writing documents before reading any from the queue, which was creating the class maps automatically on the fly. If I read a document of the same nominal type out of MongoDB, it worked flawlessly because the ClassMap had been created when I wrote a document of that type to the DB.
There were in some cases, documents in the database that may have been there for some time (days in some cases) and the application didnt have a class map for that type (because the process was restarted, for example) and so when reading the document, it could not properly determine the type.
Just figured I would explain what my problem was and how I solved it. Might be worth being archived somewhere on the web in case someone else runs into this issue. I hope it made sense.
Thanks Robert - great work on the driver. Looking forward to some LINQ goodness!