Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dotnet format crash with The solution does not contain the specified document. #2224

Open
trejjam opened this issue Jan 15, 2025 · 1 comment

Comments

@trejjam
Copy link

trejjam commented Jan 15, 2025

Hi,
since .Net 9.0.0 we can not use dotnet format on our solution.

The command that we are using:

dotnet format -v diag --no-restore whitespace My.sln

and the output:

  The dotnet runtime version is '9.0.1'.
  The dotnet CLI version is '9.0.102'.
  Using MSBuild.exe located in 'C:\Program Files\dotnet\sdk\9.0.102\'.
  Formatting code files in workspace 'D:\asp.net\My.sln'.
  Loading workspace.
Unhandled exception: System.InvalidOperationException: The solution does not contain the specified document.
   at Microsoft.CodeAnalysis.Shared.Extensions.ISolutionExtensions.GetRequiredDocument(Solution solution, DocumentId documentId)
   at Microsoft.CodeAnalysis.Workspace.<SetCurrentSolutionAsync>g__UpdateAddedDocumentToExistingContentsInSolution|27_1(Solution solution, ArrayBuilder`1 addedDocumentIds)
   at Microsoft.CodeAnalysis.Workspace.<SetCurrentSolutionAsync>g__UnifyLinkedDocumentContents|27_0(Solution oldSolution, Solution newSolution)
   at Microsoft.CodeAnalysis.Workspace.<>c.<SetCurrentSolutionAsync>b__27_3(Solution oldSolution, ValueTuple`5 data)
   at Microsoft.CodeAnalysis.Workspace.SetCurrentSolutionAsync[TData](Boolean useAsync, TData data, Func`3 transformation, Boolean mayRaiseEvents, Action`3 onBeforeUpdate, Action`3 onAfterUpdate, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Workspace.SetCurrentSolutionAsync(Boolean useAsync, Func`2 transformation, Func`3 changeKind, Action`2 onBeforeUpdate, Action`2 onAfterUpdate, CancellationToken cancellationToken)
   at Roslyn.Utilities.ValueTaskExtensions.VerifyCompleted[T](ValueTask`1 task, String message)
   at Microsoft.CodeAnalysis.Workspace.SetCurrentSolution(Func`2 transformation, Func`3 changeKind, Action`2 onBeforeUpdate, Action`2 onAfterUpdate)
   at Microsoft.CodeAnalysis.Workspace.SetCurrentSolution(Func`2 transformation, WorkspaceChangeKind changeKind, ProjectId projectId, DocumentId documentId, Action`2 onBeforeUpdate, Action`2 onAfterUpdate)
   at Microsoft.CodeAnalysis.Workspace.OnSolutionAdded(SolutionInfo solutionInfo)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.OpenSolutionAsync(String solutionFilePath, ILogger msbuildLogger, IProgress`1 progress, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Tools.Workspaces.MSBuildWorkspaceLoader.LoadAsync(String solutionOrProjectPath, WorkspaceType workspaceType, String binaryLogPath, Boolean logWorkspaceWarnings, ILogger logger, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Tools.CodeFormatter.OpenMSBuildWorkspaceAsync(String solutionOrProjectPath, WorkspaceType workspaceType, Boolean noRestore, Boolean requiresSemantics, String binaryLogPath, Boolean logWorkspaceWarnings, ILogger logger, 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.FormatWhitespaceCommand.FormatWhitespaceHandler.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
   at System.CommandLine.Invocation.InvocationPipeline.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)

The same command works when only .Net 8 is available

@trejjam
Copy link
Author

trejjam commented Jan 15, 2025

Let me know if I can provide more specific information :)
The solution starts to be quite big, and I do not know where to look for what causes this error.

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

No branches or pull requests

1 participant