microsoft / vscode-dotnettools

This is a feedback repository to capture issues logged for the C# Dev Kit and related extensions from Visual Studio Code
Other
229 stars 12 forks source link

[BUG] SDK Resolver failure when loading C# projects on Windows #666

Closed dcporter65 closed 4 months ago

dcporter65 commented 1 year ago

Describe the Issue

Loading an existing C# project in VS Code with the C# Dev Kit installed on Windows throws an SDK Resolver failure error and the project fails to load. As a result, tests and IntelliSense are unavailable in the project.

Removing the C# Dev Kit extension fixes the issue.

Steps To Reproduce

  1. Check out the dotnet/samples repo.
  2. In VS Code, with the C# Dev Kit installed, open any of the 'finished' projects in the csharp folder.

Result

The project fails to load and SDK Resolver failure errors appear in the Projects log. This happens multiple times when loading a solution with multiple projects.

Projects log output 2024-03-11 09:19:10.883 [error] (C:\Users\david.porter\Dev\samples\csharp\getting-started\console-webapiclient\webapiclient.csproj): SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.Cli.Utils, Version=7.0.406.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. File name: 'Microsoft.DotNet.Cli.Utils, Version=7.0.406.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.WorkloadSdkResolver.GetSdkDirectory(SdkResolverContext context) at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.WorkloadSdkResolver.GetDotNetRoot(SdkResolverContext context) at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.WorkloadSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory) at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.TryResolveSdkUsingSpecifiedResolvers(IList`1 resolvers, Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio, SdkResult& sdkResult, IEnumerable`1& errors, IEnumerable`1& warnings)"" 2024-03-11 09:19:10.979 [error] Failed to load project 'C:\Users\david.porter\Dev\samples\csharp\getting-started\console-webapiclient\webapiclient.csproj'. One or more errors occurred. (SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.Cli.Utils, Version=7.0.406.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. File name: 'Microsoft.DotNet.Cli.Utils, Version=7.0.406.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.WorkloadSdkResolver.GetSdkDirectory(SdkResolverContext context) at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.WorkloadSdkResolver.GetDotNetRoot(SdkResolverContext context) at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.WorkloadSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory) at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.TryResolveSdkUsingSpecifiedResolvers(IList`1 resolvers, Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio, SdkResult& sdkResult, IEnumerable`1& errors, IEnumerable`1& warnings)"" C:\Users\david.porter\Dev\samples\csharp\getting-started\console-webapiclient\webapiclient.csproj) 2024-03-11 09:19:10.987 [info] Project system initialization finished. 0 project(s) are loaded, and 1 failed to load.

Expected Behavior

The project should open without any failures.

Workaround

  1. Uninstall the C# Dev Kit extension from VS Code.
  2. Relaunch VS Code and attempt to open a sample project again.

Result

The project loads successfully without errors.

Environment Information

VSCode version: 1.87.1 C# extension: 2.8.23 C# Dev Kit extension: 1.3.10 Using OmniSharp: false

Dotnet Information .NET SDK: Version: 7.0.406 Commit: cf888f0acf Runtime Environment: OS Name: Windows OS Version: 10.0.19045 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.406\ Host: Version: 7.0.16 Architecture: x64 Commit: 567edafe61 .NET SDKs installed: 6.0.419 [C:\Program Files\dotnet\sdk] 7.0.406 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation] Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download
Visual Studio Code Extensions 42crunch.vscode-openapi@4.25.1 alexkrechik.cucumberautocomplete@2.15.2 amillard98.specflow-tools@1.1.3 bierner.markdown-mermaid@1.22.0 blackmist.linkcheckmd@0.3.1 blodwynn.featurehighlight@1.8.0 bpruitt-goddard.mermaid-markdown-syntax-highlighting@1.6.0 christian-kohler.npm-intellisense@1.4.5 clemenspeters.format-json@1.0.3 davidanson.vscode-markdownlint@0.54.0 davidnussio.vscode-jq-playground@4.3.5 docsmsft.docs-article-templates@1.0.3 docsmsft.docs-authoring-pack@1.0.1 docsmsft.docs-build@0.4.2 docsmsft.docs-images@1.0.1 docsmsft.docs-linting@0.0.13 docsmsft.docs-markdown@1.0.7 docsmsft.docs-metadata@1.0.9 docsmsft.docs-preview@1.0.5 docsmsft.docs-scaffolding@1.0.4 docsmsft.docs-yaml@1.0.1 donjayamanne.githistory@0.6.20 editorconfig.editorconfig@0.16.4 formulahendry.dotnet-test-explorer@0.7.8 formulahendry.vscode-mysql@0.5.0 foxundermoon.shell-format@7.2.5 github.vscode-pull-request-github@0.82.0 heaths.vscode-guid@1.9.0 humao.rest-client@0.25.1 jebbs.plantuml@2.17.5 jmrog.vscode-nuget-package-manager@1.1.6 jq-syntax-highlighting.jq-syntax-highlighting@0.0.2 k--kato.docomment@1.0.0 learningengineeringoperations.learn-training-ai-assistant@1.0.36 ms-azuretools.vscode-docker@1.29.0 ms-dotnettools.csdevkit@1.3.10 ms-dotnettools.csharp@2.18.16 ms-dotnettools.vscode-dotnet-runtime@2.0.2 ms-dotnettools.vscodeintellicode-csharp@0.1.26 ms-python.black-formatter@2024.0.1 ms-python.debugpy@2024.2.0 ms-python.python@2024.2.1 ms-python.vscode-pylance@2024.2.3 ms-toolsai.jupyter@2024.2.0 ms-toolsai.jupyter-keymap@1.1.2 ms-toolsai.jupyter-renderers@1.0.17 ms-toolsai.vscode-jupyter-cell-tags@0.1.8 ms-toolsai.vscode-jupyter-slideshow@0.1.5 ms-vscode-remote.remote-containers@0.348.0 ms-vscode-remote.remote-wsl@0.86.0 ms-vscode-remote.vscode-remote-extensionpack@0.25.0 ms-vscode.remote-server@1.5.1 msjsdiag.vscode-react-native@1.12.3 redhat.vscode-yaml@1.14.0 stoplight.spectral@1.1.2 streetsidesoftware.code-spell-checker@3.0.1 unifiedjs.vscode-mdx@1.8.1 waderyan.gitblame@10.9.0 yy0931.gitconfig-lsp@0.10.1
Camios commented 9 months ago

I had something similar in Visual studio 2022 v17.8.3 After rolling back to 17.6.4 I still couldn't it working (was getting a slightly different error). I repaired 17.6.4 install, then updated to 17.8 again and that seems to have resolved the problem 🤞

bronius commented 8 months ago

In my case, clicking "Restart to Update" visual studio code on m1 mac got it working again for me.

  1. Was working some time ago in whatever latest version of vscode and all the dotnet things and vscode extensions
  2. Some days had passed since I had last worked in my open vscode editors strew about my desktop
  3. I came back today to continue c#/.net on vscode on mac and saw the error in this issue
  4. I read @Camios comment above, discovered a pending vscode update ("Restart to Update" button showing), clicked, and when it came back I was in business again.
JohanBonnetGVA commented 8 months ago

UPDATE: pre release Version 1.4.28 fixed the issue .

Same here. But System.Runtime 8.0.0 is not found instead of Microsoft.DotNet.Cli.Utils.

Vs code 1.87

(everything runs fine in vs 2022 community)

DotNet info .NET SDK: Version: 8.0.200 Commit: 438cab6a9d Workload version: 8.0.200-manifests.a3c04f84 Runtime Environment: OS Name: Windows OS Version: 10.0.22631 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.200\ .NET workloads installed: [maccatalyst] Installation Source: VS 17.9.34622.214 Manifest Version: 16.4.8825-net8-rc1/8.0.100-rc.1 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.1\microsoft.net.sdk.maccatalyst\16.4.8825-net8-rc1\WorkloadManifest.json Install Type: FileBased [maui-windows] Installation Source: VS 17.9.34622.214 Manifest Version: 8.0.6/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maui\8.0.6\WorkloadManifest.json Install Type: FileBased [android] Installation Source: VS 17.9.34622.214 Manifest Version: 34.0.52/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.android\34.0.52\WorkloadManifest.json Install Type: FileBased [ios] Installation Source: VS 17.9.34622.214 Manifest Version: 16.4.8825-net8-rc1/8.0.100-rc.1 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.1\microsoft.net.sdk.ios\16.4.8825-net8-rc1\WorkloadManifest.json Install Type: FileBased Host: Version: 8.0.2 Architecture: x64 Commit: 1381d5ebd2 .NET SDKs installed: 8.0.200 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Other architectures found: arm64 [C:\Program Files\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation] x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation] Environment variables: Not set global.json file: Not found
github-actions[bot] commented 7 months ago

This issue has been marked as stale after 14 days of inactivity. @[ @ @], could you please take a look?

dcporter65 commented 6 months ago

This is still an issue for me with C# Dev Kit v1.4.29

SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.Cli.Utils, Version=7.0.407.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. File name: 'Microsoft.DotNet.Cli.Utils, Version=7.0.407.0,
Dotnet Information .NET SDK: Version: 7.0.407 Commit: 95b107dae0 Runtime Environment: OS Name: Windows OS Version: 10.0.19045 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.407\ Host: Version: 7.0.17 Architecture: x64 Commit: dff486f2d7 .NET SDKs installed: 6.0.420 [C:\Program Files\dotnet\sdk] 7.0.407 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation] Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download

As before, removing C# Dev Kit fixes the SDK Resolver error.

I did notice that the version number shown in the error has an extra ".0" after it - 7.0.407.0. The path to my SDK is simply this: C:\Program Files\dotnet\sdk\7.0.407

Michael-Eng commented 6 months ago

@lifengl can you see if the version number is an issue that's still causing a problem?

lifengl commented 5 months ago

@dcporter65 :

can you print out dotnet --info (make sure run it in the root folder of your workspace)? This might help us to know the version matrix when this problem happens.

lifengl commented 5 months ago

On the other side, I guess this might be a gap because the CDK uses a private copy of msbuild to support older SDKs, due to a version mismatching issue. It was a problem on NET 7 and older SDKs. It might lead it to fail on a newer version of NET 7 SDK (7.0.407 was released later than the CDK build of msbuild.) This private copy is a workaround, and should be phased out when the older version of SDK is no longer supported. For NET 7 SDK, it ends on May 14, 2024.

@dcporter65 : I will suggest to update to NET 8 SDK and current version of the CDK to see whether it resolves your problem.

dcporter65 commented 5 months ago

@lifengl

can you print out dotnet --info (make sure run it in the root folder of your workspace)? This might help us to know the version matrix when this problem happens.

dotnet info output

.NET SDK: Version: 7.0.408 Commit: 03a0111c2e Runtime Environment: OS Name: Windows OS Version: 10.0.19045 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.408\ Host: Version: 7.0.18 Architecture: x64 Commit: 544c7e6eb3 .NET SDKs installed: 6.0.421 [C:\Program Files\dotnet\sdk] 7.0.408 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation] Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download

dcporter65 commented 5 months ago

Update:

I have upgraded the .NET SDK to 8.0 and projects are loading successfully.

elir-castro commented 4 months ago

I'm having the same issue in .net 8.0.