You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been using dotnet format for a while now, and occasionally I'll use it on a new project and end up with an error message such as:
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)
While it's clear what this error means, it's not clear which file it's related to.
The exception is raised here, after checking if sourceText.Encoding is null. This method is called from here.
It would be useful if the exception was caught in FormatFileAsync and re-raised with some more context, such as the document file path where the source encoding could not be detected.
The text was updated successfully, but these errors were encountered:
I've been using
dotnet format
for a while now, and occasionally I'll use it on a new project and end up with an error message such as:While it's clear what this error means, it's not clear which file it's related to.
The exception is raised here, after checking if
sourceText.Encoding
is null. This method is called from here.It would be useful if the exception was caught in
FormatFileAsync
and re-raised with some more context, such as the document file path where the source encoding could not be detected.The text was updated successfully, but these errors were encountered: