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; } }