FluentValidation/FluentValidation · error · InvalidOperationException

Could not automatically determine the property name

Error message

Could not automatically determine the property name 

What it means

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.

Source

Thrown at src/FluentValidation/Internal/CollectionPropertyRule.cs:130

			return;
		}

		var cascade = CascadeMode;
		IEnumerable<TElement> collection;

		try {
			collection = PropertyFunc(context.InstanceToValidate);
		}
		catch (NullReferenceException nre) {
			throw 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);
		}

		int count = 0;
		int totalFailures = context.Failures.Count;

		if (collection != null) {
			if (string.IsNullOrEmpty(propertyName)) {
				throw new InvalidOperationException("Could not automatically determine the property name ");
			}

			foreach (var element in collection) {
				int index = count++;

				if (Filter != null && !Filter(element)) {
					continue;
				}

				if (AsyncFilter != null) {
					if (!await AsyncFilter(element)) {
						continue;
					}
#if SYNC_ONLY
					// Throw when inside the synchronous version of this method generated by Zomp.SyncMethodGenerator.
					throw new AsyncValidatorInvokedSynchronouslyException();
#endif
				}

View on GitHub (pinned to daa00b7954)

Solutions

  1. Call .OverridePropertyName("Items") (or the relevant name) on the RuleForEach chain so each element failure has a path.
  2. If validating a collection directly, wrap it in a root object so the rule can reference a named property.

Example fix

// before
RuleForEach(x => x).NotEmpty(); // x is the collection itself

// after
RuleForEach(x => x).NotEmpty().OverridePropertyName("Items");
Defensive patterns

Strategy: validation

Validate before calling

RuleForEach(x => x.Items).NotEmpty().OverridePropertyName("Items");

Prevention

When it happens

Trigger: 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.

Common situations: RuleForEach(x => x) on a collection-rooted model without overriding the property name; building rules reflectively with an expression that loses member metadata.

Related errors


AI-assisted analysis of FluentValidation/FluentValidation@daa00b7954 (2026-08-13). Data as JSON: /api/errors/01e07ba013d2cd1c. Report an issue: GitHub.