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

Handle parameterName empty string the same as null

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.19.1
    • Affects Version/s: 2.19.0
    • Component/s: LINQ3
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      MongoQueryProvider broken in v2.19, throwing the following exception:

       

      2023-02-09 10:49:08.345 +00:00 [ERR] Value cannot be empty. (Parameter 'name')
      System.ArgumentException: Value cannot be empty. (Parameter 'name')
         at MongoDB.Driver.Core.Misc.Ensure.IsNotNullOrEmpty(String value, String paramName)
         at MongoDB.Driver.Linq.Linq3Implementation.Misc.Symbol..ctor(ParameterExpression parameter, String name, AstExpression ast, IBsonSerializer serializer, Boolean isCurrent)
         at MongoDB.Driver.Linq.Linq3Implementation.Translators.TranslationContext.CreateSymbol(ParameterExpression parameter, String name, AstExpression ast, IBsonSerializer serializer, Boolean isCurrent)
         at MongoDB.Driver.Linq.Linq3Implementation.Translators.TranslationContext.CreateSymbol(ParameterExpression parameter, String name, String varName, IBsonSerializer serializer, Boolean isCurrent)
         at MongoDB.Driver.Linq.Linq3Implementation.Translators.TranslationContext.CreateSymbolWithVarName(ParameterExpression parameter, String varName, IBsonSerializer serializer, Boolean isCurrent)
         at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ExpressionToFilterTranslator.TranslateLambda(TranslationContext context, LambdaExpression lambdaExpression, IBsonSerializer parameterSerializer, Boolean asRoot)
         at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.WhereMethodToPipelineTranslator.Translate(TranslationContext context, MethodCallExpression expression)
         at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.ExpressionToPipelineTranslator.Translate(TranslationContext context, Expression expression)
         at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToExecutableQueryTranslators.CountMethodToExecutableQueryTranslator.Translate[TDocument](MongoQueryProvider`1 provider, TranslationContext context, MethodCallExpression expression)
         at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToExecutableQueryTranslators.ExpressionToExecutableQueryTranslator.TranslateScalar[TDocument,TResult](MongoQueryProvider`1 provider, Expression expression)
         at MongoDB.Driver.Linq.Linq3Implementation.MongoQueryProvider`1.Execute[TResult](Expression expression)
         at ScafellServer.DataAccess.Extensions.LinqExtensions.OptionalSkip[TSource](IQueryable`1 source, Nullable`1 count) in C:\Users\AndyBennett\source\repos\Scafell\src\ScafellServer\DataAccess\Extensions\LinqExtensions.cs:line 19

       

       

      NB. versions v2.18 and before work as expected.

      Code:

      public static IQueryable<TSource> OptionalSkip<TSource>(this IQueryable<TSource> source, int? count)
      {
          try
          {
              return count.HasValue && source?.Count() >= count.Value
                  ? source.Skip(count.Value)
                  : source;
          }
          catch (Exception ex)
          {
              Logger.Error(ex, "{Message}", ex.Message);
              return source;
          }
      } 

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            andy.bennett@ctrmcubed.com Andy Bennett
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: