{"record":{"id":"99b66b2bae519728","repo":"litedb-org/LiteDB","slug":"member-member-getpath-not-found-in-type-e","errorCode":null,"errorMessage":"Member '{member.GetPath()}' not found in type '{_entity.ForType.Name}' (use IncludeFields in BsonMapper)","messagePattern":"Member '(.+?)' not found in type '(.+?)' \\(use IncludeFields in BsonMapper\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Mapper/EntityBuilder.cs","lineNumber":108,"sourceCode":"            return this.GetMember(member, (p) =>\n            {\n                BsonMapper.RegisterDbRef(_mapper, p, _typeNameBinder, collection ?? _mapper.ResolveCollectionName(typeof(K)));\n            });\n        }\n\n        /// <summary>\n        /// Get a property based on a expression. Eg.: 'x => x.UserId' return string \"UserId\"\n        /// </summary>\n        private EntityBuilder<T> GetMember<TK, K>(Expression<Func<TK, K>> member, Action<MemberMapper> action)\n        {\n            if (member == null) throw new ArgumentNullException(nameof(member));\n            _entity.WaitForInitialization();\n            \n            var memb = _entity.GetMember(member);\n\n            if (memb == null)\n            {\n                throw new ArgumentNullException($\"Member '{member.GetPath()}' not found in type '{_entity.ForType.Name}' (use IncludeFields in BsonMapper)\");\n            }\n\n            action(memb);\n\n            return this;\n        }\n    }\n}","sourceCodeStart":90,"sourceCodeEnd":116,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Mapper/EntityBuilder.cs#L90-L116","documentation":"Thrown by the private GetMember helper in EntityBuilder when a member lambda (used by Id, Field, DbRef, or Ignore) does not match any MemberName in the entity's mapped Members list. GetMember resolves the lambda path via ExpressionExtensions.GetPath and looks it up against the Members that BuildEntityMapper populated from GetTypeMembers. The hint '(use IncludeFields in BsonMapper)' points at the most frequent cause: the target member is a field, and by default LiteDB only maps properties.","triggerScenarios":"Calling mapper.Entity<T>().Id(x => x.MyField), .Field(x => x.MyField, \"name\"), .DbRef(x => x.MyField), or .Ignore(x => x.MyField) where MyField is a public field (not a property) and mapper.IncludeFields is false. Also fires when the member has [BsonIgnore], is write-only (no getter), is an indexer (has index parameters), is static, or the lambda targets a member of a nested type rather than T itself.","commonSituations":"Using a struct or DTO with public fields and assuming they are auto-mapped. Adding [BsonIgnore] to a member and later trying to configure it via EntityBuilder. Attempting EntityBuilder configuration before setting IncludeFields on a custom BsonMapper instance. Refactoring a property into a field and forgetting to enable IncludeFields.","solutions":["If the member is a field, set mapper.IncludeFields = true before calling Entity<T>().","Ensure the member is a public instance property with a getter and no index parameters.","Remove [BsonIgnore] from the member if you need to map or configure it.","Verify the lambda references a member directly on T (e.g., x => x.Name), not a nested member (e.g., x => x.Profile.Name)."],"exampleFix":"// before\nvar db = new LiteDatabase(\"my.db\");\ndb.Mapper.Entity<MyEntity>().Field(x => x.MyField, \"my_field\");\n// throws: Member 'MyField' not found in type 'MyEntity'\n\n// after\ndb.Mapper.IncludeFields = true;\ndb.Mapper.Entity<MyEntity>().Field(x => x.MyField, \"my_field\");","handlingStrategy":"validation","validationCode":"// Before calling EntityBuilder methods, verify the member is mapped\nvar entityMapper = mapper.GetEntityMapper(typeof(T));\nif (!entityMapper.Members.Any(m => m.MemberName == \"MyField\"))\n{\n    // member is a field -- enable IncludeFields or it is ignored\n    throw new InvalidOperationException($\"Member 'MyField' is not mapped.\");\n}","typeGuard":"// Check if a member is mapped before configuring it\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    mapper.Entity<T>().Field(x => x.MyField, \"my_field\");\n}\ncatch (ArgumentNullException ex) when (ex.Message.Contains(\"not found in type\"))\n{\n    mapper.IncludeFields = true;\n    mapper.Entity<T>().Field(x => x.MyField, \"my_field\");\n}","preventionTips":["Set mapper.IncludeFields = true at mapper creation if your entities use public fields.","Prefer public auto-properties over public fields for automatic mapping.","Avoid [BsonIgnore] on members you later need to configure via EntityBuilder.","Write a startup validation pass that checks all EntityBuilder lambdas resolve to mapped members."],"tags":["mapper","entity-builder","fields","mapping"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}