litedb-org/LiteDB · error · ArgumentNullException
member
Error message
member
What it means
Thrown by EntityBuilder.GetMember (the shared helper behind Ignore, Field, Id, DbRef) when the member selector expression is null. The builder needs a non-null Expression<Func<T,K>> to resolve the target property/field. (A second throw in the same method handles a member that resolves to null with a different message; this one is specifically for a null expression argument.)
Source
Thrown at LiteDB/Client/Mapper/EntityBuilder.cs:101
}
/// <summary>
/// Define a subdocument (or a list of) as a reference
/// </summary>
public EntityBuilder<T> DbRef<K>(Expression<Func<T, K>> member, string collection = null)
{
return this.GetMember(member, (p) =>
{
BsonMapper.RegisterDbRef(_mapper, p, _typeNameBinder, collection ?? _mapper.ResolveCollectionName(typeof(K)));
});
}
/// <summary>
/// Get a property based on a expression. Eg.: 'x => x.UserId' return string "UserId"
/// </summary>
private EntityBuilder<T> GetMember<TK, K>(Expression<Func<TK, K>> member, Action<MemberMapper> action)
{
if (member == null) throw new ArgumentNullException(nameof(member));
_entity.WaitForInitialization();
var memb = _entity.GetMember(member);
if (memb == null)
{
throw new ArgumentNullException($"Member '{member.GetPath()}' not found in type '{_entity.ForType.Name}' (use IncludeFields in BsonMapper)");
}
action(memb);
return this;
}
}
}View on GitHub (pinned to f906a5f850)
Solutions
- Pass a real member selector, e.g. builder.Id(x => x.Id).
- Null-check the expression before configuring if it is built dynamically.
- If the member may not exist, catch the separate 'Member not found' message and decide whether to skip configuration.
Example fix
// before
builder.Id(idSelector); // idSelector is null
// after
if (idSelector == null)
throw new InvalidOperationException("An Id member selector must be provided.");
builder.Id(idSelector); Defensive patterns
Strategy: validation
Validate before calling
if (member == null)
throw new ArgumentException("A member selector expression is required.", nameof(member)); Prevention
- Pass concrete lambdas like x => x.Id.
- Null-check dynamically-built selectors before configuring the entity.
When it happens
Trigger: Calling builder.Id(null), builder.Ignore(null), builder.Field(null, "name"), or builder.DbRef(null), or passing an expression variable that was conditionally assigned null.
Common situations: Building a fluent mapping where some selectors are optional and a branch leaves them null, or refactoring a lambda out into a variable and forgetting to initialize it.
Related errors
AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13).
Data as JSON: /api/errors/3d5eb994f7fe6106.
Report an issue: GitHub.