fix: resolve inherited instance data source members for MethodDataSource by thomhurst · Pull Request #6178 · thomhurst/TUnit (original) (raw)

[claude[bot]](/apps/claude)

[claude[bot]](/apps/claude)

@thomhurst

…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

@thomhurst

@thomhurst thomhurst deleted the fix/6162-inherited-instance-method-data-source branch

June 7, 2026 19:57

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 }})