{"record":{"id":"01e07ba013d2cd1c","repo":"FluentValidation/FluentValidation","slug":"could-not-automatically-determine-the-property-nam","errorCode":null,"errorMessage":"Could not automatically determine the property name ","messagePattern":"Could not automatically determine the property name ","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/FluentValidation/Internal/CollectionPropertyRule.cs","lineNumber":130,"sourceCode":"\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tvar cascade = CascadeMode;\r\n\t\tIEnumerable<TElement> collection;\r\n\r\n\t\ttry {\r\n\t\t\tcollection = PropertyFunc(context.InstanceToValidate);\r\n\t\t}\r\n\t\tcatch (NullReferenceException nre) {\r\n\t\t\tthrow new NullReferenceException($\"NullReferenceException occurred when executing rule for {Expression}. If this property can be null you should add a null check using a When condition\", nre);\r\n\t\t}\r\n\r\n\t\tint count = 0;\r\n\t\tint totalFailures = context.Failures.Count;\r\n\r\n\t\tif (collection != null) {\r\n\t\t\tif (string.IsNullOrEmpty(propertyName)) {\r\n\t\t\t\tthrow new InvalidOperationException(\"Could not automatically determine the property name \");\r\n\t\t\t}\r\n\r\n\t\t\tforeach (var element in collection) {\r\n\t\t\t\tint index = count++;\r\n\r\n\t\t\t\tif (Filter != null && !Filter(element)) {\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (AsyncFilter != null) {\r\n\t\t\t\t\tif (!await AsyncFilter(element)) {\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n#if SYNC_ONLY\r\n\t\t\t\t\t// Throw when inside the synchronous version of this method generated by Zomp.SyncMethodGenerator.\r\n\t\t\t\t\tthrow new AsyncValidatorInvokedSynchronouslyException();\r\n#endif\r\n\t\t\t\t}\r","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/FluentValidation/FluentValidation/blob/daa00b795450881c233253488e3ddeb362f59f56/src/FluentValidation/Internal/CollectionPropertyRule.cs#L112-L148","documentation":"Inside CollectionPropertyRule.ValidateAsync, after the accessor returns a non-null collection, if the resolved propertyName is null or empty the rule cannot build property paths for child failures and throws InvalidOperationException. FluentValidation needs a property name to attribute each element failure to the correct path.","triggerScenarios":"A RuleForEach whose expression does not resolve to a named property and no name was supplied via OverridePropertyName, so propertyName stays empty while the collection is non-null.","commonSituations":"RuleForEach(x => x) on a collection-rooted model without overriding the property name; building rules reflectively with an expression that loses member metadata.","solutions":["Call .OverridePropertyName(\"Items\") (or the relevant name) on the RuleForEach chain so each element failure has a path.","If validating a collection directly, wrap it in a root object so the rule can reference a named property."],"exampleFix":"// before\nRuleForEach(x => x).NotEmpty(); // x is the collection itself\n\n// after\nRuleForEach(x => x).NotEmpty().OverridePropertyName(\"Items\");","handlingStrategy":"validation","validationCode":"RuleForEach(x => x.Items).NotEmpty().OverridePropertyName(\"Items\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always supply a property name for root-level RuleForEach via OverridePropertyName.","Wrap bare collections in a root object so rules reference a named property."],"tags":["fluentvalidation","property-name","ruleforeach"],"backgroundTag":null,"analyzedSha":"daa00b795450881c233253488e3ddeb362f59f56","analyzedAt":"2026-08-13T20:45:43.800Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}