dotnet/BenchmarkDotNet · error · InvalidBenchmarkDeclarationException

{sourceType.Name} has no public, accessible method/property

Error message

{sourceType.Name} has no public, accessible method/property called {sourceName}, unable to read values for [ParamsSource]

What it means

Thrown by GetValidValuesForParamsSource when the type containing [ParamsSource] does not have a public method or property with the name specified in the attribute. The method searches both GetAllMethods() and GetAllProperties() for a member matching the sourceName with public visibility; if neither is found, it throws InvalidBenchmarkDeclarationException.

Source

Thrown at src/BenchmarkDotNet/Running/BenchmarkConverter.cs:317

                return EnumParam.FromObject(providedValue, type);
            }
            return providedValue;
        }

        private static (MemberInfo source, object[] values) GetValidValuesForParamsSource(Type sourceType, string sourceName)
        {
            var paramsSourceMethod = sourceType.GetAllMethods().FirstOrDefault(method => method.Name == sourceName && method.IsPublic);

            if (paramsSourceMethod != default)
                return (paramsSourceMethod, ToArray(
                    paramsSourceMethod.Invoke(paramsSourceMethod.IsStatic ? null : Activator.CreateInstance(sourceType), null)!,
                    paramsSourceMethod,
                    sourceType));

            var paramsSourceProperty = sourceType.GetAllProperties().FirstOrDefault(property => property.Name == sourceName && property.GetMethod?.IsPublic == true);

            if (paramsSourceProperty == null)
                throw new InvalidBenchmarkDeclarationException($"{sourceType.Name} has no public, accessible method/property called {sourceName}, unable to read values for [ParamsSource]");

            return (paramsSourceProperty, ToArray(
                paramsSourceProperty.GetValue(paramsSourceProperty.GetMethod!.IsStatic ? null : Activator.CreateInstance(sourceType)!)!,
                paramsSourceProperty,
                sourceType));
        }

        private static object[] ToArray(object sourceValue, MemberInfo memberInfo, Type type)
        {
            if (!(sourceValue is IEnumerable collection))
                throw new InvalidBenchmarkDeclarationException($"{memberInfo.Name} of type {type.Name} does not implement IEnumerable, unable to read values for [ParamsSource]");

            return collection.Cast<object>().ToArray();
        }

        private static object?[] GetAllValidValues(Type parameterType)
        {
            if (parameterType == typeof(bool))

View on GitHub (pinned to b515068b61)

Solutions

  1. Use nameof() to reference the source member: [ParamsSource(nameof(MyValues))] instead of a hardcoded string.
  2. Ensure the source member is a public property or public method (not a field).
  3. Verify the member name exactly matches between the attribute and the declaration.

Example fix

// before
public IEnumerable<int> Values => new[] { 1, 2, 3 };
[Params]
[ParamsSource("MyValues")] // typo: should be "Values"
public int Number;

// after
public IEnumerable<int> Values => new[] { 1, 2, 3 };
[Params]
[ParamsSource(nameof(Values))]
public int Number;
Defensive patterns

Strategy: validation

Validate before calling

string sourceName = nameof(MyValues); // compile-time safe
var member = typeof(MyBench).GetMember(sourceName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)
    .FirstOrDefault(m => m is MethodInfo or PropertyInfo);
if (member is null)
    throw new InvalidOperationException($"No public method/property '{sourceName}' found.");

Prevention

When it happens

Trigger: Declaring [ParamsSource(nameof(MyValues))] on a field/property but the actual member 'MyValues' is misspelled, is a field (not a method/property), is non-public, or does not exist on the declaring type.

Common situations: Renaming the source member but forgetting to update the [ParamsSource] attribute string (or forgetting to use nameof). Declaring the source as a field instead of a property. Making the source method/property private or internal.

Related errors


AI-assisted analysis of dotnet/BenchmarkDotNet@b515068b61 (2026-08-13). Data as JSON: /api/errors/a3bf6c139205144b. Report an issue: GitHub.