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

Extenstion no longer accept environment variable in dotnetAcquisitionExtension.sharedExistingDotnetPath #2104

Open
PetSerAl opened this issue Jan 25, 2025 · 4 comments

Comments

@PetSerAl
Copy link

Type: Bug

Issue Description

I have dotnetAcquisitionExtension.sharedExistingDotnetPath set to ${env:ProgramFiles}\\dotnet\\dotnet.exe
It works fine with 2.55.29 but fails on 2.61.28 and pre release 2.62.18
It works fine when dotnetAcquisitionExtension.sharedExistingDotnetPath set to C:\\Program Files\\dotnet\\dotnet.exe

C# log

2025-01-25 06:50:59.305 [info] [Error - 6:50:59 AM] [LanguageServerProjectSystem] Error while loading c:\Path\Project.csproj: Exception thrown: System.UriFormatException: Failed create URI from '${env:ProgramFiles}\dotnet\packs'; original string: '${env:ProgramFiles}\dotnet\packs'
 ---> System.UriFormatException: Invalid URI: The URI scheme is not valid.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
   at System.Uri..ctor(String uriString, UriKind uriKind)
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 202
   --- End of inner exception stack trace ---
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 210
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateRelativePatternBaseUri(String path) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 227
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.FileWatching.LspFileChangeWatcher.FileChangeContext.<>c.<.ctor>b__7_0(WatchedDirectory d) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspFileChangeWatcher.cs:line 87
   at System.Linq.Enumerable.ArraySelectIterator`2.Fill(ReadOnlySpan`1 source, Span`1 destination, Func`2 func)
   at System.Linq.Enumerable.ArraySelectIterator`2.ToArray()
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.FileWatching.LspFileChangeWatcher.FileChangeContext..ctor(ImmutableArray`1 watchedDirectories, LspFileChangeWatcher lspFileChangeWatcher) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspFileChangeWatcher.cs:line 78
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.FileWatching.LspFileChangeWatcher.CreateContext(ImmutableArray`1 watchedDirectories) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspFileChangeWatcher.cs:line 44
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.FileWatching.DelegatingFileChangeWatcher.CreateContext(ImmutableArray`1 watchedDirectories) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/DelegatingFileChangeWatcher.cs:line 45
   at Microsoft.CodeAnalysis.ProjectSystem.FileWatchedReferenceFactory`1.<>c__DisplayClass6_0.<.ctor>b__0() in /_/src/Workspaces/Core/Portable/Workspace/ProjectSystem/FileWatchedPortableExecutableReferenceFactory.cs:line 68
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
--- End of stack trace from previous location ---
   at System.Lazy`1.CreateValue()
   at Microsoft.CodeAnalysis.ProjectSystem.FileWatchedReferenceFactory`1.<>c__DisplayClass7_0.<StartWatchingReference>b__0(String _) in /_/src/Workspaces/Core/Portable/Workspace/ProjectSystem/FileWatchedPortableExecutableReferenceFactory.cs:line 127
   at Roslyn.Utilities.IDictionaryExtensions.GetOrAdd[K,V](IDictionary`2 dictionary, K key, Func`2 function) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/IDictionaryExtensions.cs:line 21
   at Microsoft.CodeAnalysis.ProjectSystem.FileWatchedReferenceFactory`1.StartWatchingReference(String fullFilePath) in /_/src/Workspaces/Core/Portable/Workspace/ProjectSystem/FileWatchedPortableExecutableReferenceFactory.cs:line 125
   at Microsoft.CodeAnalysis.Workspaces.ProjectSystem.ProjectSystemProjectFactory.ApplyProjectUpdateState(ProjectUpdateState projectUpdateState) in /_/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProjectFactory.cs:line 430
   at Microsoft.CodeAnalysis.Workspaces.ProjectSystem.ProjectSystemProjectFactory.ApplyBatchChangeToWorkspaceMaybe_NoLockAsync(Boolean useAsync, Func`3 mutation, Action`1 onAfterUpdateAlways) in /_/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProjectFactory.cs:line 348
   at Microsoft.CodeAnalysis.Workspaces.ProjectSystem.ProjectSystemProjectFactory.ApplyBatchChangeToWorkspaceMaybeAsync(Boolean useAsync, Func`3 mutation, Action`1 onAfterUpdateAlways) in /_/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProjectFactory.cs:line 294
   at Microsoft.CodeAnalysis.Workspaces.ProjectSystem.ProjectSystemProject.OnBatchScopeDisposedMaybeAsync(Boolean useAsync) in /_/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.cs:line 577
   at Microsoft.CodeAnalysis.Workspaces.ProjectSystem.ProjectSystemProject.BatchScope.DisposeAsync() in /_/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.cs:line 546
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.UpdateWithNewProjectInfoAsync(ProjectFileInfo newProjectInfo, ILogger logger) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 238
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.LoadOrReloadProjectAsync(ProjectToLoad projectToLoad, ToastErrorReporter toastErrorReporter, BuildHostProcessManager buildHostProcessManager, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 284

Environment information

Extension version: 2.62.18
VS Code version: Code 1.96.3 (91fbdddc47bc9c09064bf7acf133d22631cbf083, 2025-01-09T18:14:09.060Z)
OS version: Windows_NT x64 10.0.26100

@JoeRobich
Copy link
Member

@nagilson Should we move this to vscode-dotnet-runtime?

@nagilson
Copy link
Member

nagilson commented Jan 28, 2025

Yeah.

We dont do parsing on the string, we just treat it as the raw executable path. So it tries to run ${env:ProgramFiles}\\dotnet\\dotnet.exe --info in the cmd, which isn't going to work. At least that's my guess. How it worked before is a bit surprising to me, but we never validated the executable by calling it beforehand, so maybe it got parsed by some other handler somehow. Im also surprised VS Code doesn't parse this if that's allowed when we try to read the value.

@nagilson
Copy link
Member

Admittedly, the exception likely shouldn't be thrown like that. If you wanna do better handling that would be in the C# end

@nagilson
Copy link
Member

Btw for now you can also set this setting and I believe that would allow you to keep the env

Image

@JoeRobich JoeRobich transferred this issue from dotnet/vscode-csharp Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants