{"record":{"id":"67b8cee720c84e07","repo":"litedb-org/LiteDB","slug":"member-name-not-found-on-bsonmapper-for-type-me","errorCode":null,"errorMessage":"Member {name} not found on BsonMapper for type {member.DeclaringType}.","messagePattern":"Member (.+?) not found on BsonMapper for type (.+?)\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs","lineNumber":643,"sourceCode":"\n        /// <summary>\n        /// Returns document field name for some type member\n        /// </summary>\n        private string ResolveMember(MemberInfo member, out MemberMapper memberMapper)\n        {\n            var name = member.Name;\n\n            // checks if parent field are not DbRef (checks for same dataType)\n            var isParentDbRef = _dbRefType != null && member.DeclaringType.IsAssignableFrom(_dbRefType);\n\n            // get class entity from mapper\n            var entity = _mapper.GetEntityMapper(member.DeclaringType);\n            entity.WaitForInitialization();\n\n            // get mapped field from entity\n            var field = entity.Members.FirstOrDefault(x => x.MemberName == name);\n\n            memberMapper = field ?? throw new NotSupportedException($\"Member {name} not found on BsonMapper for type {member.DeclaringType}.\");\n\n            // define if this field are DbRef (child will need check parent)\n            _dbRefType = field.IsDbRef ? field.UnderlyingType : null;\n\n            // if parent call is DbRef and are calling _id field, rename to $id\n            return \".\" + (isParentDbRef && field.FieldName == \"_id\" ? \"$id\" : field.FieldName);\n        }\n\n        /// <summary>\n        /// Define if this method is index access and must eval index value (do not use parameter)\n        /// </summary>\n        private bool IsMethodIndexEval(MethodCallExpression node, out Expression obj, out Expression idx)\n        {\n            var method = node.Method;\n            var type = method.DeclaringType;\n            var pars = method.GetParameters();\n\n            // for List/Dictionary [int/string]","sourceCodeStart":625,"sourceCodeEnd":661,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs#L625-L661","documentation":"Thrown by the private ResolveMember helper in LinqExpressionVisitor when a member accessed in a LINQ query is not found in the entity's mapped Members list. Unlike error 60 (which fires during EntityBuilder configuration), this fires during query translation when the visitor tries to resolve a member path against the BsonMapper's EntityMapper for the declaring type. The member name must match a MemberName in entity.Members.","triggerScenarios":"Querying x => x.UnmappedMember where the member is not in the entity's mapped Members: it could be a field (IncludeFields is false), have [BsonIgnore], lack a getter, be an indexer, or belong to a type whose mapping hasn't been configured. Also fires if a member of a nested type in the path is not mapped.","commonSituations":"Querying a public field without IncludeFields enabled. Querying a [BsonIgnore]'d member. Querying a member added to the class after the mapper was first used without reconfiguration. Querying a computed read-only property that has no backing field (though getters-only properties are mapped if CanRead is true -- the issue is usually fields or ignored members).","solutions":["Ensure the member is a public instance property with a getter and is not marked [BsonIgnore].","If the member is a field, set mapper.IncludeFields = true before querying.","Register the member explicitly via mapper.Entity<T>().Field(x => x.Member, \"field_name\").","Verify the member name in the lambda exactly matches a mapped MemberName."],"exampleFix":"// before -- querying an unmapped field\ncol.Find(x => x._internalScore > 50);\n// throws: Member '_internalScore' not found on BsonMapper\n\n// after -- enable fields or map explicitly\nvar mapper = new BsonMapper { IncludeFields = true };\n// or:\nmapper.Entity<MyEntity>().Field(x => x._internalScore, \"score\");\ncol.Find(x => x._internalScore > 50);","handlingStrategy":"validation","validationCode":"// Verify a member is mapped before using it in a query\nvar entityMapper = mapper.GetEntityMapper(typeof(T));\nif (!entityMapper.Members.Any(m => m.MemberName == nameof(T.TargetMember)))\n{\n    throw new InvalidOperationException($\"Member is not mapped.\");\n}\ncol.Find(x => x.TargetMember > 0);","typeGuard":"// Check if a member is mapped before querying\nstatic bool IsMemberMapped<T>(BsonMapper mapper, string memberName)\n{\n    var em = mapper.GetEntityMapper(typeof(T));\n    return em.Members.Any(m => m.MemberName == memberName);\n}","tryCatchPattern":"try\n{\n    var results = col.Find(x => x.UnmappedField > 0);\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"not found on BsonMapper for type\"))\n{\n    mapper.IncludeFields = true;\n    results = col.Find(x => x.UnmappedField > 0);\n}","preventionTips":["Enable mapper.IncludeFields if querying public fields.","Remove [BsonIgnore] from members you need to query.","Register members explicitly via Entity<T>().Field() before querying.","Write a startup check that validates all queried members exist in the entity mapping."],"tags":["linq","member-access","mapping"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}