title: BsonSerializationException when serializing a Dictionary<DateTime,T> to BSON
body: <p>I've recently moved to the <a href="https://www.nuget.org/packages/MongoDB.Driver/2.0.0" rel="noreferrer">new MongoDB C# driver v2.0</a> from the <a href="https://www.nuget.org/packages/mongocsharpdriver/2.0.0" rel="noreferrer">deprecated v1.9</a>.</p>
  
  <p>Now, when I serialize a class that has a dictionary I sometimes run into the following <code>BsonSerializationException</code>:</p>
  
  <blockquote>
    <p>MongoDB.Bson.BsonSerializationException: When using DictionaryRepresentation.Document key values must serialize as strings.</p>
  </blockquote>
  
  <p>Here's a minimal reproduce:</p>
  
  <pre><code>class Hamster
  {
      public ObjectId Id { get; private set; }
      public Dictionary&lt;DateTime,int&gt; Dictionary { get; private set; }
      public Hamster()
      {
          Id = ObjectId.GenerateNewId();
          Dictionary = new Dictionary&lt;DateTime, int&gt;();
          Dictionary[DateTime.UtcNow] = 0;
      }
  }
  </code></pre>
  
  <p></p>
  
  <pre><code>static void Main()
  {
      Console.WriteLine(new Hamster().ToJson());
  }
  </code></pre>