I have a nested class (I don't know why, or if it's relevant);
public partial class Foo: Bar
{
public class InnerFoo
{
...
}
}
InnerFoo get's serialized as 'Object' so gets automatically annoted with _t: "InnerFoo". I'm using automatic serialization and all works fine most of the time. However, I recently started seeing failures. After stepping through the driver source I discovered that InnerFoo was indeed missing from BsonSerializer.__discriminators. In fact, for the same program that list seems a different length every time I look at it, it's astounding it works the rest of the time.
It turns out that if I *Serialize* an InnerFoo first, it populates the list and works fine. However, if my code tries to "Deserialize" before it's ever Serialized, which is highly likely with web server process recycling it will fail to have the discriminator.
Q: How can I ensure that my discriminators are *fully* populated. I should probably turn OFF the auto-population since that's a disaster waiting to happen.