Skip to content

Conversation

@glennawatson
Copy link
Contributor

Problem

Users reported CS0579 "Duplicate 'GeneratedCodeAttribute' attribute" errors when using Splat.DependencyInjection.SourceGenerator v2.1.1 alongside ReactiveUI.SourceGenerators v2.5.1. This occurred because both partial class declarations of SplatRegistrations (in Splat.DI.g.cs and Splat.DI.Reg.g.cs) were applying the [GeneratedCodeAttribute] attribute, causing a compilation error.

Changes

Bug Fixes

  • Fixed duplicate attribute error: Removed [GeneratedCodeAttribute] from the generated Splat.DI.Reg.g.cs file. The attribute now only appears once on the partial class in Splat.DI.g.cs, eliminating the CS0579 error
  • Fixed RegisterConstant signature: Added where T : class constraint to match Splat's API, preventing CS0452 type constraint errors

Documentation Improvements

  • Enhanced XML documentation in Constants.cs: All registration methods now include:

    • Detailed <summary> descriptions explaining transient vs singleton behavior
    • Complete <typeparam> documentation for generic type parameters
    • Proper <param> tags with clear explanations
    • <see cref=""> references to related types
    • <remarks> sections explaining analyzer diagnostics and attribute behavior
  • Added XML documentation to generated code: The generated Splat.DI.Reg.g.cs now includes:

    • Class-level documentation explaining the partial class structure
    • Method-level documentation for SetupIOCInternal with parameter descriptions
    • <see cref=""> references for better IntelliSense navigation

Testing & Project Organization

  • Reorganized test structure: Moved test projects to src/tests/ for better organization
  • Added TestApp: Created Splat.DI.SourceGenerator.TestApp to reproduce and verify the duplicate attribute issue with real-world scenarios
  • Added regression tests: New test GenerateSetupIOCMethod_DoesNotIncludeDuplicateGeneratedCodeAttribute ensures the attribute only appears once
  • Updated 393 snapshot tests to reflect the improved generated code format

Impact

  • Resolves compatibility issues with ReactiveUI.SourceGenerators and other source generators
  • Improves developer experience with comprehensive IntelliSense documentation
  • Better code maintainability with properly documented generated code
  • All 834 tests passing

…ocumentation

## Problem
Users reported CS0579 "Duplicate 'GeneratedCodeAttribute' attribute" errors when using
Splat.DependencyInjection.SourceGenerator v2.1.1 alongside ReactiveUI.SourceGenerators v2.5.1.
This occurred because both partial class declarations of `SplatRegistrations` (in Splat.DI.g.cs
and Splat.DI.Reg.g.cs) were applying the `[GeneratedCodeAttribute]` attribute, causing a
compilation error.

## Changes

### Bug Fixes
- **Fixed duplicate attribute error**: Removed `[GeneratedCodeAttribute]` from the generated
  `Splat.DI.Reg.g.cs` file. The attribute now only appears once on the partial class in
  `Splat.DI.g.cs`, eliminating the CS0579 error
- **Fixed RegisterConstant<T> signature**: Added `where T : class` constraint to match
  Splat's API, preventing CS0452 type constraint errors

### Documentation Improvements
- **Enhanced XML documentation in Constants.cs**: All registration methods now include:
  - Detailed `<summary>` descriptions explaining transient vs singleton behavior
  - Complete `<typeparam>` documentation for generic type parameters
  - Proper `<param>` tags with clear explanations
  - `<see cref="">` references to related types
  - `<remarks>` sections explaining analyzer diagnostics and attribute behavior

- **Added XML documentation to generated code**: The generated `Splat.DI.Reg.g.cs` now includes:
  - Class-level documentation explaining the partial class structure
  - Method-level documentation for `SetupIOCInternal` with parameter descriptions
  - `<see cref="">` references for better IntelliSense navigation

### Testing & Project Organization
- Reorganized test structure: Moved test projects to `src/tests/` for better organization
- Added TestApp: Created `Splat.DI.SourceGenerator.TestApp` to reproduce and verify the
  duplicate attribute issue with real-world scenarios
- Added regression tests: New test `GenerateSetupIOCMethod_DoesNotIncludeDuplicateGeneratedCodeAttribute`
  ensures the attribute only appears once
- Updated 393 snapshot tests to reflect the improved generated code format

## Impact
- ✅ Resolves compatibility issues with ReactiveUI.SourceGenerators and other source generators
- ✅ Improves developer experience with comprehensive IntelliSense documentation
- ✅ Better code maintainability with properly documented generated code
- ✅ All 834 tests passing

## Breaking Changes
None. This is a bug fix release with backward-compatible improvements.
… length issues

Removed EmitCompilerGeneratedFiles and CompilerGeneratedFilesOutputPath settings from
TestApp.csproj. These were causing CI failures on Windows due to path length limitations
with ReactiveUI.SourceGenerators generated files.

The generated code can still be inspected through obj/ folders during local development
if needed, but won't be committed to the repository.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a duplicate GeneratedCodeAttribute compilation error and enhances documentation for the Splat DI Source Generator. The main issue was that both partial class declarations in generated files had the [GeneratedCodeAttribute], causing CS0579 errors.

Changes:

  • Removed duplicate [GeneratedCodeAttribute] from Splat.DI.Reg.g.cs generated files
  • Added where T : class constraint to RegisterConstant<T> methods to match Splat's API
  • Enhanced XML documentation throughout the codebase

@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.41%. Comparing base (77bd4e9) to head (875f5d5).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #289      +/-   ##
==========================================
+ Coverage   94.03%   94.41%   +0.38%     
==========================================
  Files          17       17              
  Lines         838      896      +58     
  Branches      145      145              
==========================================
+ Hits          788      846      +58     
  Misses         19       19              
  Partials       31       31              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@glennawatson glennawatson enabled auto-merge (squash) January 22, 2026 11:28
@glennawatson glennawatson merged commit 7967f28 into main Jan 22, 2026
6 checks passed
@glennawatson glennawatson deleted the glennawatson/fix-double-rego branch January 22, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants