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

VSCode Debugger Environment Variable Case Sensitivity Causes DLL Loading Issues #241570

Closed
MrPresidentCh opened this issue Feb 22, 2025 · 4 comments
Assignees
Labels
*caused-by-extension Issue identified to be caused by an extension info-needed Issue requires more information from poster

Comments

@MrPresidentCh
Copy link

Type: Bug

Description:
On Windows, VSCode's launch.json configuration file treats environment variables Path and PATH as case-sensitive. However, Windows itself does not distinguish between Path and PATH, and only recognizes Path for DLL loading. If PATH is incorrectly used in launch.json, the program may fail to load DLL files during debugging.

Steps to Reproduce:

Create a simple program that requires a DLL file to be loaded.
In launch.json, incorrectly configure the environment variable as PATH instead of Path (e.g., "name": "PATH", "value": "C:\path\to\dlls").
When debugging, the program will fail to load the DLL, showing an error.
Changing PATH to Path in launch.json resolves the issue and allows the DLL to be loaded.
Actual Behavior:
Using PATH does not affect DLL loading in Windows, causing DLLs to not be found during debugging.

Expected Behavior:
VSCode should handle environment variables uniformly and not differentiate between Path and PATH, ensuring that DLLs can be loaded successfully during debugging.

Suggested Solution:
Fix the issue in VSCode where environment variables are treated case-sensitively in launch.json. Ensure that both Path and PATH are treated identically to avoid DLL loading issues.

VS Code version: Code 1.97.2 (e54c774, 2025-02-12T23:20:35.343Z)
OS version: Windows_NT x64 10.0.19045
Modes:

System Info
Item Value
CPUs AMD Ryzen 3 3200G with Radeon Vega Graphics (4 x 3593)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 15.95GB (7.05GB free)
Process Argv --crash-reporter-id b3bb9a5d-7db1-4dd9-95fc-227712ac9688
Screen Reader no
VM 0%
Extensions (18)
Extension Author (truncated) Version
cpp-helper ami 0.3.4
format-astyle DIZ 1.1.6
copilot Git 1.272.0
copilot-chat Git 0.24.1
helium-icon-theme hel 1.0.0
vscode-lua-format Koi 1.3.8
cortex-debug mar 1.12.1
debug-tracker-vscode mcu 0.0.15
memory-view mcu 0.0.25
peripheral-viewer mcu 1.4.6
rtos-views mcu 0.0.7
vscode-language-pack-zh-hans MS- 1.97.2025021209
cpptools ms- 1.23.6
cpptools-extension-pack ms- 1.3.0
hexeditor ms- 1.11.1
material-icon-theme PKi 5.19.0
lua sum 3.13.6
str-transform xzz 0.0.2

(1 theme extensions excluded)

A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vscod805:30301674
binariesv615:30325510
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dwnewjupyter:31046869
nativerepl2:31139839
pythonrstrctxt:31112756
nativeloc2:31192216
iacca1:31171482
5fd0e150:31155592
dwcopilot:31170013
stablechunks:31184530
6074i472:31201624
dwoutputs:31242946
customenabled:31241370
hdaa2157:31222309
copilot_t_ci:31222730
jda6j935:31233686

@roblourens
Copy link
Member

What is the type of your launch config?

@roblourens roblourens added the info-needed Issue requires more information from poster label Feb 23, 2025
@mdtuttle
Copy link

mdtuttle commented Feb 28, 2025

I have the same issue. The trick is to get VSCode to launch with both a "Path" and "PATH" environment variable.

It can be reproduced with the following recipe:

  1. From Windows, open a Command Prompt
  2. Type, "set path".
  3. If there already a "Path" (case-sensitive) environment variable, go to Step 7., "Start a Python session"
  4. Type and execute: set path2=%path%
  5. Type and execute: set path=
  6. Type and execute (case-sensitive): set Path=%path2%
  7. Start a Python session (I don't think the version matters. I am running Python 3.13.1)
  8. Execute the following in the Python session

import os
import subprocess
new_path = r"c:\SomeArbitraryExistingPathThatIsNotAlreadyInThePathEnvironmentVariable" (Use your own path here)
os.environ['path'] = f"{os.getenv('path')};{new_path}"
subprocess.Popen('start cmd', shell=True, env=os.environ)

  1. In the new Command Prompt, launch VSCode, "code ."
  2. From within VSCode, start a new integrated terminal Command Prompt
  3. Type and execute: set path

This will show two path environment variables. One "Path" and one "PATH".
Trying to run something from "SomeArbitraryExistingPathThatIsNotAlreadyInThePathEnvironmentVariable" will fail.
Notice that deleting "Path" with "set Path", will delete the "Path" environment variable and leave the "PATH".
Running something from "SomeArbitraryExistingPathThatIsNotAlreadyInThePathEnvironmentVariable" will now succeed.

VSCode Version: 1.97.2 (system setup)
Commit: e54c774
Date: 2025-02-12T23:20:35.343Z
Electron: 32.2.7
ElectronBuildId: 10982180
Chromium: 128.0.6613.186
Node.js: 20.18.1
V8: 12.8.374.38-electron.0
OS: Windows_NT x64 10.0.19045

@MrPresidentCh
Copy link
Author

What is the type of your launch config?您的启动配置类型是什么?

To verify this process is quite simple with the following configuration in launch.json:

json

复制
{
"configurations": [
{
"name": "C/C++ gdb",
"type": "cppdbg",
"request": "launch",
// other
"environment": [
{
"name": "Path",
"value": "c:\xb"
}
]
}
]
}
In the environment variable settings, the value of "name" is case-sensitive. When it is "Path" instead of "PATH" or "PAth," it represents two distinct environment variables. You can create a C program to retrieve this variable for verification, such as using printf(getenv("path")) to display the variable's value. If the name is "Path" instead of "PATH," the output will show the difference between the two environment variables. The getenv function is also case-sensitive in order to obtain the correct value.

However, it appears that in typical scenarios, using system APIs to set the PATH environment variable or using batch commands like set path does not differentiate between uppercase and lowercase. This case sensitivity seems to occur only in the configuration of Visual Studio Code.

@roblourens
Copy link
Member

Thanks, please file this on the repo for the C++ debug extension

@roblourens roblourens added the *caused-by-extension Issue identified to be caused by an extension label Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
*caused-by-extension Issue identified to be caused by an extension info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants