fix: resolve inherited instance data source members for MethodDataSource by thomhurst · Pull Request #6178 · thomhurst/TUnit (original) (raw)
[](/apps/claude)
[](/apps/claude)
…rce (#6162)
[MethodDataSource] targeting an instance member combined with [InheritsTests] and a class-level DI data source crashed with "No parameterless constructor defined" because the engine fell back to Activator.CreateInstance.
Source-gen mode: GenerateMethodDataSourceAttribute resolved the data source member via GetMembers on the derived test class only, which misses members declared on base classes. The member lookup now walks the base-type chain so inherited members get the InstanceMethodDataSourceAttribute conversion and a compiled Factory, the same as members declared directly on the test class.
Reflection mode: plain MethodDataSourceAttributes targeting an instance member were never upgraded to InstanceMethodDataSourceAttribute, so the engine never pre-created a properly-constructed instance. ExtractMethodDataSources now performs the same conversion the source generator does at compile time.
Adds a regression test reproducing the issue: an abstract base class with an instance property data source, inherited by a sealed class whose instances are produced by a DependencyInjectionDataSourceAttribute.
Fixes #6162
- Move the InstanceMethodDataSourceAttribute conversion onto MethodDataSourceAttribute (internal ToInstanceVariant) so property copying lives with the type instead of in the extractor.
- Promote MethodDataSourceAttribute.BindingFlags to internal and reference it from ReflectionAttributeExtractor, removing the duplicated constant.
- Replace the GetMethod + AmbiguousMatchException catch with GetMember enumeration: overloaded names no longer skip the conversion, and any instance overload conservatively triggers it.
- Public API snapshots: compiler-generated async state machine renamed d__21 -> d__22 (member ordinal shift from the new internal method); no public surface change.
thomhurst deleted the fix/6162-inherited-instance-method-data-source branch
This was referenced
Jun 8, 2026
This was referenced
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})