{"record":{"id":"b28f1f21cb941992","repo":"dotnet/efcore","slug":"no-backing-field-was-found-for-property-1-entity","errorCode":null,"errorMessage":"No backing field was found for property '{1_entityType}.{0_property}'. Name the backing field so that it is discovered by convention, configure the backing field to use, or use a different '{propertyAccessMode}'.","messagePattern":"No backing field was found for property '(.+?)\\.(.+?)'\\. Name the backing field so that it is discovered by convention, configure the backing field to use, or use a different '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Scaffolding/Internal/CSharpRuntimeModelCodeGenerator.cs","lineNumber":1805,"sourceCode":"\n            property.AddRuntimeAnnotation(CoreAnnotationNames.UnsafeAccessors, accessors.Take(i).ToArray());\n        }\n\n        return memberAccessReplacements;\n    }\n\n    private QualifiedName? RegisterPrivateAccessor(\n        IPropertyBase property,\n        bool forMaterialization,\n        bool forSet,\n        string @namespace,\n        BidirectionalDictionary<Type, string> unsafeAccessorClassNames,\n        Dictionary<Type, HashSet<MemberInfo>> unsafeAccessorTypes,\n        ref Dictionary<MemberInfo, QualifiedName>? memberAccessReplacements)\n    {\n        if (!property.TryGetMemberInfo(forMaterialization, forSet, out var member, out var error))\n        {\n            throw new InvalidOperationException(error);\n        }\n\n        if (member == null)\n        {\n            return null;\n        }\n\n        switch (member)\n        {\n            case FieldInfo field:\n            {\n                if (field.IsPublic\n                    || (memberAccessReplacements?.ContainsKey(field)) == true)\n                {\n                    return null;\n                }\n\n                break;","sourceCodeStart":1787,"sourceCodeEnd":1823,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Scaffolding/Internal/CSharpRuntimeModelCodeGenerator.cs#L1787-L1823","documentation":"Thrown by RegisterPrivateAccessor when property.TryGetMemberInfo(...) returns false, meaning EF cannot resolve a usable backing member (field or property accessor) for the property under the requested access mode. The compiled model uses [UnsafeAccessor] to reach non-public members and needs a concrete FieldInfo/MethodInfo; if none is found it throws InvalidOperationException with the error string produced by TryGetMemberInfo (CoreStrings.NoBackingField).","triggerScenarios":"Compiled-model generation for a property with a PropertyAccessMode (e.g. Field, FieldDuringConstruction) that requires a backing field, but no backing field was discovered or configured.","commonSituations":"Using SetPropertyAccessMode/SetFieldAccessMode to Field when the property has no conventionally-discovered backing field and none was configured; auto-properties whose compiler-generated field name does not match the convention after renaming; fields marked in ways that defeat discovery.","solutions":["Explicitly configure the backing field with .HasField(\"_fieldName\") or .UsePropertyAccessMode(PropertyAccessMode.Property).","Name the backing field so EF discovers it by convention (e.g. _name, m_name, <Property>k__BackingField).","Switch the access mode to one that does not require a field (e.g. PropertyAccessMode.Property)."],"exampleFix":"// before\nmodelBuilder.Entity<E>().Property(p => p.Secret).UsePropertyAccessMode(PropertyAccessMode.Field); // no field\n// after\nmodelBuilder.Entity<E>().Property(p => p.Secret).HasField(\"_secret\").UsePropertyAccessMode(PropertyAccessMode.Field);","handlingStrategy":"validation","validationCode":"// Verify each property can resolve a backing member under its access mode\nforeach (var prop in model.GetEntityTypes().SelectMany(e => e.GetProperties()))\n{\n    if (!prop.TryGetMemberInfo(forMaterialization: false, forSet: true, out _, out var error))\n        Console.WriteLine($\"{prop.DeclaringType}.{prop.Name}: {error}\");\n}","typeGuard":null,"tryCatchPattern":"try { Optimize(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"backing field\"))\n{ /* call .HasField(\"...\") or change PropertyAccessMode, then regenerate */ }","preventionTips":["Name backing fields by convention (_field, m_field) so EF discovers them.","Call .HasField(\"...\") when the field name is unconventional.","Avoid Field access modes on properties with no backing field."],"tags":["compiled-model","backing-field","property-access-mode","unsafe-accessors","scaffolding"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}