Skip to content

dotnet format command replaces some line endings when comments precede multi-line strings #52249

Open

Description

@filzrev

Describe the bug

When comment exists before C# multi-line string.
dotnet format command replace some line endings unexpectedly.

Example code to format

public void Test()
{
    var text =
        // Comment before multiline string.
        """
        line1
        line2
        line3
        """;
}

To Reproduce

Run following steps on Windows environment with .NET 10 SDK.

  1. Create console app with dotnet new console command
  2. Edit Program.cs and add sample code described above.
  3. Run dotnet format --verify-no-changes -v diag and confirms there is no diff.
  4. Switch to WSL2 (Ubuntu) and run same command. and confirms errors are shown.
    /mnt/c/Temp/ConsoleApp/Program.cs(4,11): error WHITESPACE: Fix whitespace formatting. Replace 10 characters with '\n\s\s\s\s\s\s\s\s'. [/mnt/c/Temp/ConsoleApp/ConsoleApp.csproj]
    /mnt/c/Temp/signoz/ConsoleApp.cs(5,44): error WHITESPACE: Fix whitespace formatting. Replace 10 characters with '\n\s\s\s\s\s\s\s\s'. [/mnt/c/Temp/ConsoleApp/ConsoleApp.csproj]
    

When running without --verify-no-changes option.
It replace line endings before and after comment line.
And it cause mixed line encodings (CRLF/LF)

It's not expected line endings are modified by dotnet format command
when end_of_line is not specified by .editorconfig explicitly.

Exceptions (if any)

It seems caused when using .NET 10 SDK.
When running on .NET 9. It's not occurred.

Further technical details

I've tested with .NET 10 SDK 10.0.101.

Activity

  1. added
    untriaged
    on Dec 19, 2025
  2. added this to the Backlog milestone on Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Formatuntriaged

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions