Skip to content

ParamsSource attribute doesn't work as expected #848

Closed

Description

@evilguest

The properties marked with the ParamsSource attribute aren't set in the ExecutionValidatorBase.
This causes issues when this validator calls the GlobalSetup.
The property marked as this does work as expected (gets inited to the first listed value before calling the GlobalSetup method):

        [Params(
            typeof(BasicTestSet),
            typeof(UnsafeTestSet),
            typeof(SlowDeferredLinqTestSet),
            typeof(FastLinqTestSet),
            typeof(UnsafeLinqTestSet),
            typeof(UnsafeParallelTestSet)
        )]
        public Type FilterType { get; set; }

The property marked as this doesn't work as expected - it remains null upon the GlobalSetup method call:

        [ParamsSource(nameof(GetTestTypes))]
        public Type FilterType { get; set; }
        public static IEnumerable<Type> GetTestTypes() => new[] {typeof(BasicTestSet),
            typeof(UnsafeTestSet),
            typeof(SlowDeferredLinqTestSet),
            typeof(FastLinqTestSet),
            typeof(UnsafeLinqTestSet),
            typeof(UnsafeParallelTestSet)};

The root cause is in the ExecutionValidatorBase.TryToSetParamsProperties code. It just scans the properties for the Params attribute, ignoring the ParamsSource attribute:

var paramProperties = benchmarkTypeInstance
                .GetType()
                .GetAllProperties()
                .Where(propertyInfo => propertyInfo.GetCustomAttributes(false).OfType<ParamsAttribute>().Any())
.ToArray();

Instead it should rely on a common init code, like ReturnValueValidator does:
InProcessRunner.FillMembers(benchmarkTypeInstance, benchmark);

Activity

  1. AndreyAkinshin commented on Aug 9, 2018

    @AndreyAkinshin
    Member

    @evilguest thanks for the report!
    @adamsitnik could you take a look?

  2. removed their assignment
    on Aug 9, 2018
  3. adamsitnik commented on Aug 9, 2018

    @adamsitnik
    Member

    @AndreyAkinshin I don't have time ;( I am finishing the CoreFX port ;)

    @evilguest would you like to send a PR? you did a great job finding the source of the problem and now you are one step away from becoming a BenchmarkDotNet contributor!

  4. added this to the v0.13.x milestone on Oct 23, 2020
  5. removed this from the v0.14.x milestone on Dec 3, 2025
  6. added this to the v0.16.0 milestone on May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions