Skip to content

TUNU0001 code fixer crashes on multi-targeting projects #4485

@thomhurst

Description

@thomhurst

Description

The TUNU0001 NUnit migration code fixer crashes when running dotnet format analyzers --severity info --diagnostics TUNU0001 on projects that target multiple frameworks.

Reproduction Steps

  1. Create a test project with multiple target frameworks:
<PropertyGroup>
    <TargetFrameworks>net8.0;net9.0;net10.0;net462</TargetFrameworks>
</PropertyGroup>
  1. Add TUnit and NUnit packages:
<PackageReference Include="TUnit" Version="1.11.*" />
<PackageReference Include="NUnit" Version="3.14.0" />
  1. Run the code fixer:
dotnet format analyzers --severity info --diagnostics TUNU0001

Expected Behavior

The code fixer should process all files and apply migrations.

Actual Behavior

The code fixer crashes with the following exception:

Unhandled exception: System.AggregateException: One or more errors occurred. (Changes must be within bounds of SourceText (Parameter 'changes'))
 ---> System.ArgumentException: Changes must be within bounds of SourceText (Parameter 'changes')
   at Microsoft.CodeAnalysis.Text.SourceText.WithChanges(IEnumerable`1 changes)
   at Microsoft.CodeAnalysis.LinkedFileMergeConflictCommentAdditionService.GetCommentChangesForDocument(...)
   ...

Workaround

Temporarily change the project to use a single target framework:

<TargetFramework>net10.0</TargetFramework>

Then run the code fixer, and restore multi-targeting afterward.

Environment

  • TUnit version: 1.11.64
  • .NET SDK: 10.0.102
  • OS: Windows

Suggested Fix

The code fixer should handle multi-targeting projects by processing files for a single TFM at a time, or by properly merging changes across linked file instances.

Tests should be added to verify the code fixer works correctly with multi-targeting projects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingduplicateThis issue or pull request already exists

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions