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

Compiler error: ambiguous call between IEnumerable<MongoDB.Bson.BsonValue> and IEnumerable<object> in BsonArray

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.2
    • Affects Version/s: 1.1
    • Component/s: None
    • Labels:
    • Major Change

      *) Build environment:
      VS 2010, Target platform: .NET 3.5, driver versions: 1.1 both official and the latest sources

      *) Steps to reproduce:
      Add the following method to the MongoDB.BsonUnitTests.BsonArrayTests:

      void TestCompilerError()
      var values = new BsonValue[] { };

      // all 3 calls cannot compile
      var array = new BsonArray(values);

      .. and compile. Compilation fails with an error (3 similar errors):

      The call is ambiguous between the following methods or properties: 'MongoDB.Bson.BsonArray.Create(System.Collections.Generic.IEnumerable<MongoDB.Bson.BsonValue>)' and 'MongoDB.Bson.BsonArray.Create(System.Collections.Generic.IEnumerable<object>)'

      *) Possible solution:
      Remove 3 methods dealing with System.Collections.Generic.IEnumerable<object> from MongoDB.Bson.BsonArray (constructor, Create, AddRange). As it was mentioned in https://jira.mongodb.org/browse/CSHARP-276, these methods are redundant after adding methods dealing with non-generic IEnumerable. Now they seem to be also troublesome.

      I tried to remove these 3 methods from the latest sources. The test code is compiled successfully.

            robert@mongodb.com Robert Stam
            nightroman Roman Kuzmin
            0 Vote for this issue
            0 Start watching this issue