Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1879

InvalidOperationException thrown when registered ClassMap is not frozen

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.4.2
    • Affects Version/s: 2.0
    • Component/s: Serialization
    • Labels:
      None

      BsonClassMap.RegisterClassMap(map) will accept an unfrozen map silently, but later on fail with the following when used:

      Unhandled Exception: System.InvalidOperationException: {document}.Id is not supported.
         at MongoDB.Driver.Linq.Translators.PredicateTranslator.GetFieldExpression(Expression expression)
         at MongoDB.Driver.Linq.Translators.PredicateTranslator.TranslateComparison(Expression variableExpression, ExpressionType operatorType, ConstantExpression constantExpression)
         at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node)
         at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
         at MongoDB.Driver.MongoCollectionImpl`1.ConvertWriteModelToWriteRequest(WriteModel`1 model, Int32 index)
         at System.Linq.Enumerable.<SelectIterator>d__148`2.MoveNext()
         at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.BatchHelper.<FindOrderedRuns>d__8.MoveNext()
         at MongoDB.Driver.Core.Misc.ReadAheadEnumerable`1.ReadAheadEnumerator.MoveNext()
         at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.BatchHelper.<GetBatches>d__6.MoveNext()
         at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.Execute(IWriteBinding binding, CancellationToken cancellationToken)
         at MongoDB.Driver.OperationExecutor.ExecuteWriteOperation[TResult](IWriteBinding binding, IWriteOperation`1 operation, CancellationToken cancellationToken)
         at MongoDB.Driver.MongoCollectionImpl`1.ExecuteWriteOperation[TResult](IWriteOperation`1 operation, CancellationToken cancellationToken)
         at MongoDB.Driver.MongoCollectionImpl`1.BulkWrite(IEnumerable`1 requests, BulkWriteOptions options, CancellationToken cancellationToken)
         at MongoDB.Driver.MongoCollectionBase`1.ReplaceOne(FilterDefinition`1 filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken)
         at MongoDB.Driver.IMongoCollectionExtensions.ReplaceOne[TDocument](IMongoCollection`1 collection, Expression`1 filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken)
         at ConsoleApplication.Program.Repro(IMongoCollection`1 coll)
         at ConsoleApplication.Program.Main(String[] args)
      

      BsonClassMap.RegisterClassMap(map) should either throw an exception when it is called with an unfrozen map or call map.Freeze() itself.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            james.kovacs@mongodb.com James Kovacs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: