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

System.Exception: Restore operation failed. #1560

Open
kthompson opened this issue Mar 25, 2022 · 10 comments
Open

System.Exception: Restore operation failed. #1560

kthompson opened this issue Mar 25, 2022 · 10 comments

Comments

@kthompson
Copy link

kthompson commented Mar 25, 2022

When running dotnet format style -v diag i get an exception as follows:

  The dotnet runtime version is '6.0.3'.
  The dotnet CLI version is '6.0.103'.
  Using MSBuild.exe located in 'C:\Program Files\dotnet\sdk\6.0.201\'.
  Formatting code files in workspace 'D:\code\work\platform\apps\ciri\Ciri.sln'.
  Loading workspace.

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.FormatStyleCommand.FormatStyleHandler.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()

dotnet format --version results with 6.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?

@BrightSoul
Copy link

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()

@analogrelay
Copy link

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.

@kardiojack
Copy link

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.

@JoeRobich
Copy link
Member

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.

@wzchua
Copy link

wzchua commented Aug 12, 2022

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

NickGraham101 added a commit to DFE-Digital/teaching-record-system that referenced this issue Dec 29, 2022
dotnet-format started failing after bumping setup-dotnet to v3
it looks like the cause of the failure is:
dotnet/format#1560
this was probably succeeding previously because it was using the version
preinstalled on the runner until the breaking change introduced with
[email protected] which caused the preinstalled version to be
overwritten:
https://github.com/actions/setup-dotnet/releases/tag/v3.0.0
NickGraham101 added a commit to DFE-Digital/teaching-record-system that referenced this issue Dec 30, 2022
dotnet-format started failing after bumping setup-dotnet to v3
it looks like the cause of the failure is:
dotnet/format#1560
this was probably succeeding previously because it was using the version
preinstalled on the runner until the breaking change introduced with
[email protected] which caused the preinstalled version to be
overwritten:
https://github.com/actions/setup-dotnet/releases/tag/v3.0.0
@ctyar-qc
Copy link

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.

@dimaaan
Copy link

dimaaan commented Feb 23, 2023

In my case it was failing because of a reference to non-existing version of the package in a csproj file

@jspraul
Copy link

jspraul commented Jun 16, 2023

--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).

@richard-collette-precisely

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.

@nico-abram
Copy link

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?)

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