Open kthompson opened 2 years ago
It was working fine for me with SDK 6.0.100 but then, when I updated to 6.0.201, it started giving out errors. I then installed the global tool dotnet-format
and it gave more errors. Now, even if I uninstalled the global tool and reverted my global.json
to 6.0.100, it wouldn't work anymore. Same error as this issue.
$> dotnet format
Unhandled exception: System.Exception: Restore operation failed.
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.RootFormatCommand.FormatCommandDefaultHandler.InvokeAsync(InvocationContext context)
at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass27_0.<<UseVersionOption>b__1>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__24_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseDebugDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()
Same problem here. On installing SDK 6.0.201, I started getting this error. It persisted even after uninstalling that SDK version.
I was able to workaround it by removing all installed .NET SDKs (I'm on macOS so I did sudo rm -Rf /usr/local/share/dotnet
) and then reinstalling just SDK 6.0.103. Not ideal at all, but a possible workaround for others affected by this.
Any update on this? dotnet format
works locally with 6.0.202 and
dotnet format --version
6.2.315104+eb87be219a075ad9401cd5dd3cab14288a55b59b
but I have had to take it out of my GH Actions CI because it throws the aforementioned exception.
The GH Action runner has the same versions of dotnet CLI/SDK and dotnet format as above.
Does running dotnet restore
work from the commandline? At the moment format is invoking that command as the restore operation.
As a workaround you can pass the --no-restore
flag to dotnet-format. You may need to add a CI step to perform the dotnet restore
prior to running format.
From the logs, it seems to be using the msbuild from the latest sdk instead of the one in the sdk defined in global.json
We were suddenly seeing the same error message.
The underlying issue was something else.
dotnet restore
was failing because of a duplicate reference in a csproj file. Removing that fixed the issue.
I think the dotnet format
can show a better error message here.
In my case it was failing because of a reference to non-existing version of the package in a csproj file
--no-restore
also was enough for me
Maybe dotnet format could display a warning message ("restore failed and may need to be run separately beforehand") instead of crashing?
This started after updating Visual Studio 2022 and affects the previous SDK (eg. 6.0.118 fails, 6.0.313 works).
This just started happening to me. My docker build worked fine locally but when running in gitlab agent using Kaniko on a Platform9 cluster, this started popping up.
I was getting this error, figured out that it was because I have msvc's vcvarsall.bat in my powershell profile (startup script) which sets the PLATFORM env var to x64 which results in this error (I have no .sln.metaproj file, it was inferring the config from that env var I think?)
When running
dotnet format style -v diag
i get an exception as follows:dotnet format --version
results with6.0.252703+68bc36719088c86b0ff01334039b0611741b8276
Also, this issue does not appear when running under CI with the same repo.
Any guidance on how I might be able to investigate further?