litedb-org/LiteDB · error · NotSupportedException

Method {Reflection.MethodName(node.Method)} in {node.Method.

Error message

Method {Reflection.MethodName(node.Method)} in {node.Method.DeclaringType.Name} are not supported when convert to BsonExpression ({node.ToString()}).

What it means

Thrown by VisitMethodCall when a resolver DOES exist for the method's declaring type but ResolveMethod returns null for the specific method overload. The declaring type is recognized, but this particular method (or overload) is not in the resolver's known set. The full method signature is shown via Reflection.MethodName for clarity.

Source

Thrown at LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs:241

            if (!hasResolver)
            {
                // if method are called by parameter expression and it's not exists, throw error
                var isParam = ParameterExpressionVisitor.Test(node);

                if (isParam) throw new NotSupportedException($"Method {node.Method.Name} not available to convert to BsonExpression ({node.ToString()}).");

                // otherwise, try compile and execute
                var value = this.Evaluate(node);

                base.Visit(Expression.Constant(value));

                return node;
            }

            // otherwise I have resolver for this method
            var pattern = type.ResolveMethod(node.Method);

            if (pattern == null) throw new NotSupportedException($"Method {Reflection.MethodName(node.Method)} in {node.Method.DeclaringType.Name} are not supported when convert to BsonExpression ({node.ToString()}).");

            // run pattern using object as # and args as @n
            this.ResolvePattern(pattern, node.Object, node.Arguments);

            return node;
        }

        /// <summary>
        /// Visit :: x => x.Age + `10` (will create parameter:  `p0`, `p1`, ...)
        /// </summary>
        protected override Expression VisitConstant(ConstantExpression node)
        {
            var value = node.Value;

            // https://stackoverflow.com/a/29708655/3286260
            foreach (var memberAccessNode in _memberAccessNodes)
            {
                if (memberAccessNode.Member is FieldInfo fieldInfo)

View on GitHub (pinned to f906a5f850)

Solutions

  1. Use a supported overload of the method (e.g., the parameterless or single-argument variant that the resolver recognizes).
  2. Hoist the computation into a closure variable if it produces a constant for the query.
  3. Use a raw BsonExpression string if the equivalent operation is supported in BsonExpression syntax.
  4. Check the type resolver source (e.g., StringResolver, DateTimeResolver) for the exact supported method list.

Example fix

// before
col.Find(x => x.Name.IndexOf("ab", 0, StringComparison.OrdinalIgnoreCase) >= 0);

// after -- use the supported Contains overload
col.Find(x => x.Name.Contains("ab"));
Defensive patterns

Strategy: validation

Validate before calling

// Check the resolver source for supported method overloads before using them
// StringResolver supports: Contains, StartsWith, EndsWith, ToUpper, ToLower, Substring
// Avoid unsupported overloads (e.g., IndexOf with StringComparison)
var test = mapper.GetExpression<MyEntity, bool>(x => x.Name.Contains("abc"));

Try / catch

try
{
    var results = col.Find(x => x.Name.IndexOf("ab", StringComparison.OrdinalIgnoreCase) >= 0);
}
catch (NotSupportedException ex) when (ex.Message.Contains("are not supported when convert to BsonExpression"))
{
    results = col.Find(x => x.Name.Contains("ab"));
}

Prevention

When it happens

Trigger: Calling a method on a resolver-backed type using an unsupported overload. For example x => x.Name.IndexOf("ab", StringComparison.OrdinalIgnoreCase) where StringResolver does not support that specific IndexOf overload, or x => x.Value.ToString("X") on a numeric type whose resolver lacks that pattern.

Common situations: Using an uncommon overload of a supported method (different parameter count or types). Passing format strings or comparison options that the resolver does not handle. Upgrading LiteDB and finding a previously-tolerated overload now explicitly rejected.

Related errors


AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13). Data as JSON: /api/errors/9592c1225c162527. Report an issue: GitHub.