ExportXMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Blocker - P1
    • 10.0.6, 9.1.6, 8.4.6
    • Affects Version/s: None
    • Component/s: None
    • None
    • Dotnet Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Applications using the MongoDB EF Core provider with EF Core 10, or earlier compatible versions, should be able to run on newer .NET runtimes without failing because additional framework method overloads have been introduced.

      The current implementation resolves several methods through reflection using only the method name and parameter count. For example:

       

      private static readonly MethodInfo QueryableJoinMethod =
          typeof(Queryable).GetMethods()
              .Single(m => m.Name == nameof(Queryable.Join)
                           && m.GetParameters().Length == 5);
      

      .NET 11 introduces additional Queryable.Join overloads, including another overload with five parameters. Consequently, this lookup matches multiple methods and .Single() throws an InvalidOperationException during static initialization.

       

      This prevents affected query translation code from initializing, even though the original overload remains available.

      Expected behavior

      The provider should resolve the exact overload it requires. Adding other overloads in a newer runtime should not break existing functionality or require an EF Core major-version upgrade solely to address this lookup failure.

      Proposed solution

      Replace name-and-parameter-count lookups with explicitly typed expression trees. The compiler selects the intended overload, and its generic method definition is extracted from the resulting MethodCallExpression:

       

      {{private static readonly MethodInfo QueryableJoinMethod =
      GetQueryableJoinMethodDefinition();

      private static MethodInfo GetQueryableJoinMethodDefinition()
      => ((MethodCallExpression)((Expression<Func<
      IQueryable<object>,
      IEnumerable<object>,
      Expression<Func<object, object>>,
      Expression<Func<object, object>>,
      Expression<Func<object, object, object>>,
      IQueryable<object>>>)
      ((outer, inner, outerKey, innerKey, resultSelector) =>
      Queryable.Join(
      outer, inner, outerKey, innerKey, resultSelector))).Body)
      .Method.GetGenericMethodDefinition();}}

       

      I have applied this approach locally to several method resolvers, including Queryable.Join, Queryable.GroupJoin, and Mql.Field.

      Not all of them are currently broken, but for alignment and future-proofing the setup, all similar setups should be improved

       

            Assignee:
            Damien Guard
            Reporter:
            Jan Willem Broumels (EXT)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: