litedb-org/LiteDB · error · NotSupportedException
Member are not support in when convert to BsonExpression (…
Error message
Member {member.Name} are not support in {member.DeclaringType.Name} when convert to BsonExpression ({node.ToString()}). What it means
Thrown by VisitMember when a member is accessed on a type that has a registered ITypeResolver (e.g., String, DateTime, Guid, Int32, ObjectId, Regex, Math) but that resolver's ResolveMember returns null for the specific member. This means the declaring type is recognized, but the particular property or field is not in the resolver's known pattern set.
Solutions
- Use only the members that the built-in resolvers support (for DateTime: Year, Month, Day, Hour, Minute, Second; for String: Length and standard methods like Contains/StartsWith/ToUpper).
- Hoist the computation out of the query: fetch results with a supported predicate, then compute the unsupported member in memory.
- If a raw BsonExpression equivalent exists for the operation, use a string-based query instead of LINQ.
Example fix
// before var recent = col.Find(x => x.CreatedAt.DayOfYear > 1); // DayOfYear is not in DateTimeResolver // after var recent = col.Find(x => x.CreatedAt.Month >= 1 && x.CreatedAt.Day > 1);
Defensive patterns
Strategy: validation
Validate before calling
// Check the resolver source for supported members before using them in queries // DateTimeResolver supports: Year, Month, Day, Hour, Minute, Second // StringResolver supports: Length // Avoid: Ticks, Millisecond, DayOfYear, Chars var testExpr = mapper.GetExpression<MyEntity, bool>(x => x.CreatedAt.Year > 2020);
Try / catch
try
{
var results = col.Find(x => x.CreatedAt.DayOfYear > 1);
}
catch (NotSupportedException ex) when (ex.Message.Contains("are not support in"))
{
results = col.Find(x => x.CreatedAt.Year >= 2020);
} Prevention
- Familiarize yourself with the supported members in each ITypeResolver.
- Keep a reference list of supported members for built-in types near your query code.
- Write unit tests for each LINQ predicate to catch unsupported members at test time.
- Prefer simple member comparisons (Year, Month, Day, Length) over exotic properties.
When it happens
Trigger: Accessing a member on a resolver-backed type that the resolver does not support. For example x => x.CreatedAt.Ticks (DateTime has a resolver but Ticks is not a supported pattern) or x => x.Name.Chars (String has a resolver but Chars is not supported).
Common situations: Using a less common property of a built-in type (DateTime.Ticks, DateTime.Millisecond, String.Chars) that the resolver does not map. Expecting full parity with .NET's API surface when only a curated subset is translated. Refactoring from a supported member to an unsupported one.
Related errors
- Constructor for are not supported when convert to…
- Member not found on BsonMapper for type .
- Method not available to convert to BsonExpression inside…
- Method not available to convert to BsonExpression ( ).
- Method in are not supported when convert to BsonExpression…
AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13).
Data as JSON: /api/errors/7cf83680ebc80a20.
Report an issue: GitHub.
Appendix: source
Thrown at LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs:143
return base.VisitParameter(node);
}
/// <summary>
/// Visit :: x => x.`Customer.Name`
/// </summary>
protected override Expression VisitMember(MemberExpression node)
{
// test if member access is based on parameter expression or constant/external variable
var isParam = ParameterExpressionVisitor.Test(node);
var member = node.Member;
// special types contains method access: string.Length, DateTime.Day, ...
if (TryGetResolver(member.DeclaringType, out var type))
{
var pattern = type.ResolveMember(member);
if (pattern == null) throw new NotSupportedException($"Member {member.Name} are not support in {member.DeclaringType.Name} when convert to BsonExpression ({node.ToString()}).");
this.ResolvePattern(pattern, node.Expression, new Expression[0]);
}
else
{
// for static member, Expression == null
if (node.Expression != null)
{
_memberAccessNodes.Push(node);
base.Visit(node.Expression);
if (isParam)
{
var name = this.ResolveMember(member, out _);
_builder.Append(name);
}View on GitHub (pinned to f906a5f850)