Repository navigation
Closed
Copy link
Labels
Description
Describe the bug
It is no longer possible to use dotnet format without arguments to format code in certain projects because it has started throwing an error in 9.0.200. dotnet format --verify-no-changes does still work however.
What's worse, it doesn't specify what file might be the issue so it is very hard to figure out what might be going wrong.
To Reproduce
I'm not exactly sure since it doesn't tell me what file it has a problem with, but I'm just running dotnet format in an ASP.NET Core 9 project with about 1500 C# files.
Exceptions (if any)
Unhandled exception: System.Exception: source text did not have an identifiable encoding
at Microsoft.CodeAnalysis.Tools.Formatters.CharsetFormatter.IsEncodingEquivalent(SourceText sourceText, Encoding encoding)
at Microsoft.CodeAnalysis.Tools.Formatters.CharsetFormatter.<>c__DisplayClass10_0.<FormatFileAsync>b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
at Microsoft.CodeAnalysis.Tools.Formatters.DocumentFormatter.GetFormattedSourceTextAsync(Document document, OptionSet optionSet, AnalyzerConfigOptions analyzerConfigOptions, FormatOptions formatOptions, ILogger logger, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Tools.Formatters.DocumentFormatter.<>c__DisplayClass8_1.<<FormatFiles>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.CodeAnalysis.Tools.Formatters.DocumentFormatter.ApplyFileChangesAsync(Solution solution, ImmutableArray`1 formattedDocuments, FormatOptions formatOptions, ILogger logger, List`1 formattedFiles, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Tools.Formatters.DocumentFormatter.FormatAsync(Workspace workspace, Solution solution, ImmutableArray`1 formattableDocuments, FormatOptions formatOptions, ILogger logger, List`1 formattedFiles, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Tools.CodeFormatter.RunCodeFormattersAsync(Workspace workspace, Solution solution, ImmutableArray`1 formattableDocuments, FormatOptions formatOptions, ILogger logger, List`1 formattedFiles, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Tools.CodeFormatter.FormatWorkspaceAsync(FormatOptions formatOptions, ILogger logger, CancellationToken cancellationToken, String binaryLogPath)
at Microsoft.CodeAnalysis.Tools.FormatCommandCommon.FormatAsync(FormatOptions formatOptions, ILogger`1 logger, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Tools.Commands.RootFormatCommand.FormatCommandDefaultHandler.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
at System.CommandLine.Invocation.InvocationPipeline.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
Further technical details
The error started showing up after installing Visual Studio 17.3, but it is also happening in WSL2 with the latest .NET SDK.
Reacted by Christian Daniel, Mario Adam, Christopher Currens, Adam Knights, Caleb Lloyd, C-J Berg, Will Rogers, Andrew Alkema, Michal Zatloukal, Lucas Teles and 39 more
Reacted by Eric Sondergard, Lucas Teles and Mari Teiler-Johnsen
Activity
DavidZidar commentedon Feb 12, 2025
I did try running
dotnet format --verbosity diagbut did not receive any additional actionable information.adam-knights commentedon Feb 12, 2025
Incase its useful in fixing this, we see similar today having taken 9.0.200, but on Windows only, our Mac arm64 users do not see the errors. May not apply to all cases, but if someone is looking at this and can't reproduce, try Windows.
caleblloyd commentedon Feb 12, 2025
I am hitting this on linux after the 9.0.200 upgrade today. Same deal,
--verbosity diagdoesn't show any other useful information. Reverting to 9.0.103 fixes.ChrisTTian667 commentedon Feb 13, 2025
I'm a Mac ARM 64 User and have the same issue. I don't think that its related to the platform.
MattEdwardsWaggleBee commentedon Feb 14, 2025
I'm seeing this on my Windows 11 machine and my GitHub action running on "ubuntu-latest"
update: I'm on
9.0.200co-worker doesn't see this on9.0.103CICD: dotnet format using 9.0.103
swharden commentedon Feb 15, 2025
Thanks for opening this issue and following-up with your suggestions!
I'm here to report I fixed this by locking the dotnet version to
9.0.103too, as shown in ScottPlot/ScottPlot@57c9b02david-driscoll commentedon Feb 16, 2025
I'm also hitting this as well on a mac m4.
Kiruyuto commentedon Feb 17, 2025
This happened to me today, Win11 and .NET 9.0.200.
In my case, it was related to the fact that some files had UTF-8-BOM encoding which they should not (Per
.editorconfig). Runningdotnet format --severity info -v diag --verify-no-changesto locate them and then removing it via Rider fixed the usualdotnet format.21 remaining items
Preserve encoding during DocumentState updates
Preserve encoding during DocumentState updates
Merge main to runtime async branch (#77533)
rubo commentedon Mar 11, 2025
When will the fix be released? v9.0.201 still has this problem.
mattmc-jtb commentedon Mar 11, 2025
Agreed rubo. I'm surprised this wasn't considered a critical fix since
dotnet formathas been effectively broken for a month.just-jim commentedon Mar 12, 2025
So when should we expect to see the fix? In which version?
JoeRobich commentedon Mar 13, 2025
The fix merged into the 9.0.2xx branch and will be in the 9.0.202 SDK. I have verified the fix in the 9.0.300 nightly SDK (see https://github.com/dotnet/sdk/blob/main/documentation/package-table.md) build as well.
dqwork commentedon Mar 26, 2025
When would 9.0.202 be included with Visual Studio - Just updated to the latest (17.13.5) and only got SDK 9.0.201 which still has this bug
Pin SDK to .net 8
Pin SDK to .net 8 (#88)
mtmk commentedon May 12, 2025
fyi I was having the same issue (even after removing BOM) and wasted about an hour before I found this issue.
Upgrading to latest (as of today
9.0.203) fixed it for me.idgogoasa commentedon May 15, 2025
Running
dotnet format --verify-no-changeswill list the files that need encoding changes
Did that, fixed the encoding using Notepad++ and all is OK.
jantrmer commentedon May 23, 2025
I was having the same issue, and downloading and installing SDK 9.0.300 fixed it. Release date: May 13, 2025. Thanks.