using MongoDB.Bson.Serialization;
using MongoDB.Driver;

namespace MongoDriverBug
{
    class Program
    {
        static void Main(string[] args)
        {

            BsonSerializer.RegisterSerializer(typeof(Identity), new IdentitySerializer());
            BsonSerializer.RegisterIdGenerator(typeof(Identity?), new IdentityGenerator());
            
            var svr = MongoServer.Create();
            var db = svr.GetDatabase("mongoDriverBug");
            var col = db.GetCollection<Order>("orders");

            var order = new Order { Amount = 100 };
            col.Save(order);

            order.Amount = 200;
            col.Save(order); // this line throws an exception
        }
    }
}
