{"record":{"id":"189d80e106998b8b","repo":"litedb-org/LiteDB","slug":"method-met-method-name-not-available-to-convert","errorCode":null,"errorMessage":"Method {met.Method.Name} not available to convert to BsonExpression inside Any/All call.","messagePattern":"Method (.+?) not available to convert to BsonExpression inside Any/All call\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs","lineNumber":582,"sourceCode":"                // requires only parameter in left side\n                if (bin.Left.NodeType != ExpressionType.Parameter) throw new LiteException(0, \"Any/All requires simple parameter on left side. Eg: `x => x.Phones.Select(p => p.Number).Any(n => n > 5)`\");\n\n                var op = this.GetOperator(bin.NodeType);\n\n                _builder.Append(op);\n\n                this.VisitAsPredicate(bin.Right, false);\n            }\n            // Visit .Any(x => `x.StartsWith(\"John\")`)\n            else if (expression is MethodCallExpression met)\n            {\n                // requires only parameter in left side\n                if (met.Object.NodeType != ExpressionType.Parameter) throw new NotSupportedException(\"Any/All requires simple parameter on left side. Eg: `x.Customers.Select(c => c.Name).Any(n => n.StartsWith('J'))`\");\n\n                // if not found in resolver, try run method\n                if (!TryGetResolver(met.Method.DeclaringType, out var type))\n                {\n                    throw new NotSupportedException($\"Method {met.Method.Name} not available to convert to BsonExpression inside Any/All call.\");\n                }\n\n                // otherwise I have resolver for this method\n                var pattern = type.ResolveMethod(met.Method);\n\n                if (pattern == null || !pattern.StartsWith(\"#\")) throw new NotSupportedException($\"Method {met.Method.Name} not available to convert to BsonExpression inside Any/All call.\");\n\n                // call resolve pattern removing first `#`\n                this.ResolvePattern(pattern.Substring(1), met.Object, met.Arguments);\n            }\n            else\n            {\n                throw new LiteException(0, \"When using Any/All method test do only simple predicate variable. Eg: `x => x.Phones.Select(p => p.Number).Any(n => n > 5)`\");\n            }\n\n        }\n\n        /// <summary>","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs#L564-L600","documentation":"Thrown by VisitEnumerablePredicate when, inside an Any/All lambda, a method is called whose declaring type has no registered ITypeResolver. The resolver lookup (TryGetResolver) fails, so LiteDB has no way to translate the method into BsonExpression within the Any/All context.","triggerScenarios":"Inside an Any/All lambda, calling a method on a type that has no resolver. For example x.Items.Select(i => i.Tag).Any(t => t.IsMatch(\"x\")) where the Tag type has no resolver.","commonSituations":"Calling custom methods on user-defined types within Any/All predicates. Assuming LiteDB can evaluate arbitrary .NET methods inside enumerable predicates.","solutions":["Restructure the query to Select a primitive (String, Int32, etc.) before Any/All so the method is on a resolver-backed type.","Replace the method call with a direct comparison against a mapped field.","Post-filter in memory if the operation cannot be expressed in BsonExpression."],"exampleFix":"// before\ncol.Find(x => x.Items.Select(i => i.Tag).Any(t => t.IsMatch(\"x\")));\n// Tag type has no resolver\n\n// after -- compare a mapped string field instead\ncol.Find(x => x.Items.Any(i => i.Tag == \"x\"));","handlingStrategy":"validation","validationCode":"// Ensure methods inside Any/All are on resolver-backed types (String, Int32, etc.)\n// Instead of: .Select(i => i.CustomObj).Any(t => t.IsMatch(\"x\"))\n// Use: .Any(i => i.Tag == \"x\") where Tag is a string","typeGuard":null,"tryCatchPattern":"try\n{\n    var results = col.Find(x => x.Items.Select(i => i.Tag).Any(t => t.IsMatch(\"x\")));\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"not available to convert to BsonExpression inside Any/All\"))\n{\n    results = col.Find(x => x.Items.Any(i => i.Tag == \"x\"));\n}","preventionTips":["Only use methods on resolver-backed types (String, etc.) inside Any/All predicates.","Select a primitive field before Any/All so the method operates on a known type.","Keep Any/All predicates simple and backed by String or numeric comparisons."],"tags":["linq","any-all","method-call","resolver"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}