Skip to content

ClassDataSource in partial classes "breaks" compilation when compiling. warning CS8785 #3231

@MadsLjungberg

Description

@MadsLjungberg

Summary

When using partial classes together with ClassDataSource, the source generators (DataSourceHelpersGenerator and PropertyInjectionSourceGenerator) fail due to duplicate "hintName" values.

Minimal Repro

public partial class Tests
{
    [Test]
    public void Basic()
    {
        Console.WriteLine("This is a basic test");
    }
}

public partial class Tests
{
    [ClassDataSource<DataClass>(Shared = SharedType.PerTestSession)]
    public required DataClass DataClass { get; init; }
}

Actual Behaviour

Compilation produces the following warnings/errors:

`CSC : warning CS8785: Generator 'DataSourceHelpersGenerator' failed to generate source.
It will not contribute to the output and compilation errors may occur as a result.
Exception was of type 'ArgumentException' with message
'The hintName 'PartialTest_Tests_DataSourceHelper.g.cs' of the added source file
must be unique within a generator. (Parameter 'hintName')'.

CSC : warning CS8785: Generator 'PropertyInjectionSourceGenerator' failed to generate source.
It will not contribute to the output and compilation errors may occur as a result.
Exception was of type 'ArgumentException' with message
'The "hintName" 'PartialTest_Tests_PropertyInjection.g.cs' of the added source file
must be unique within a generator. (Parameter 'hintName')'.`

Expected Behaviour

Partial classes should work seamlessly with ClassDataSource without causing duplicate "hintName" collisions in the generated files.
This is probably du to the source generator assigning hintName as some internal thing or not gripping the name of the violator.

Notes

Tested with partial class split across two files.

Works fine if everything is placed in a single class declaration.

Unsure if this is intended or a bug in the generators’ handling of partials.

Tested on the newest version 0.61.39

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions