Skip to content

No error from IntelliSense when assigning void expression to var-type local variable #9269

@BenDeegan1001

Description

@BenDeegan1001

Type: Bug

Issue Description

If C# code includes a simultaneous declaration and assignment of a local variable of type var, where the expression to assign is of type void (e.g. Console.Writeline()), there is no error message from C# IntelliSense.
If the variable name is hovered over, a popup appears with the text "(local variable) void ". However, this does not compile, since variables may not be of type void.

Steps to Reproduce

  1. Create a C# source file.
  2. Enter a local variable declaration-and-assignment statement where the local variable is of type var and the expression to assign is a method returning void, e.g. "var t = Console.WriteLine();"

Expected Behavior

Red underlining of the statement from IntelliSense, and popup on hover along the lines of "error CS0815: Cannot assign void to an implicitly-typed variable", along with an "unused variable" style suggestion.

Actual Behavior

No red error message from IntelliSense, and popup on hover of "(local variable) void t", along with the expected style suggestion about an unused variable.

Extension version: 2.130.5
VS Code version: Code 1.118.1 (034f571df509819cc10b0c8129f66ef77a542f0e, 2026-04-29T17:36:44+03:00)
OS version: Windows_NT x64 10.0.26200
Modes:

Logs

C# log

Details
2026-05-02 15:52:17.156 [info] Locating .NET runtime version 10.0.5
2026-05-02 15:52:17.211 [info] Dotnet path: C:\Program Files\dotnet\dotnet.exe
2026-05-02 15:52:17.211 [info] Activating C# standalone...
2026-05-02 15:52:17.734 [info] info: Program[0]
2026-05-02 15:52:17.734 [info]       Server started with process ID 31384
2026-05-02 15:52:20.348 [info] [Program] Language server initialized
2026-05-02 15:52:20.351 [info] [Program] Monitoring client process 30936 for exit
2026-05-02 15:52:21.467 [info] [textDocument/diagnostic] [Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager] .NET BuildHost started from c:\Users\Jennifer Deegan\.vscode\extensions\ms-dotnettools.csharp-2.130.5-win32-x64\.roslyn\Microsoft.CodeAnalysis.LanguageServer.exe reloading to start from C:\Program Files\dotnet\dotnet.exe to match necessary SDK location.
2026-05-02 15:52:22.642 [warning] [textDocument/diagnostic] [LanguageServerProjectLoader] Project C:\Users\Jennifer Deegan\AppData\Local\Temp\roslyn-canonical-misc\6b29be63-ba78-4e83-8866-6458010de4aa\Canonical.csproj has unresolved dependencies
2026-05-02 15:52:22.759 [info] [textDocument/diagnostic] [LanguageServerProjectLoader] Successfully completed load of C:\Users\Jennifer Deegan\AppData\Local\Temp\roslyn-canonical-misc\6b29be63-ba78-4e83-8866-6458010de4aa\Canonical.cs
2026-05-02 15:52:22.764 [info] [textDocument/diagnostic] [LanguageServerProjectLoader] Restoring Canonical.cs: Running dotnet restore on C:\Users\Jennifer Deegan\AppData\Local\Temp\roslyn-canonical-misc\6b29be63-ba78-4e83-8866-6458010de4aa\Canonical.cs
2026-05-02 15:52:22.765 [info] [textDocument/diagnostic] [Microsoft.CodeAnalysis.LanguageServer.DotnetCliHelper] Using dotnet executable configured on the PATH
2026-05-02 15:52:23.493 [info] [textDocument/diagnostic] [LanguageServerProjectLoader] Restoring Canonical.cs:   Determining projects to restore...
2026-05-02 15:52:24.057 [info] [textDocument/diagnostic] [LanguageServerProjectLoader] Restoring Canonical.cs:   Restored C:\Users\Jennifer Deegan\AppData\Local\Temp\roslyn-canonical-misc\6b29be63-ba78-4e83-8866-6458010de4aa\Canonical.csproj (in 267 ms).
2026-05-02 15:52:24.102 [info] [textDocument/diagnostic] [LanguageServerProjectLoader] Restore complete
2026-05-02 15:52:24.102 [info] [textDocument/diagnostic] [LanguageServerProjectLoader] Completed (re)load of all projects in 00:00:02.9184613

C# LSP Trace Logs log

Details

Environment Information

VSCode version: 1.118.1
C# Extension: 2.130.5
Using OmniSharp: false

Dotnet Information .NET SDK: Version: 10.0.203 Commit: c23858a6d8 Workload version: 10.0.200-manifests.ef86bccd MSBuild version: 18.3.3+c23858a6d

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26200
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.203\

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.7
Architecture: x64
Commit: b16286c228

.NET SDKs installed:
9.0.313 [C:\Program Files\dotnet\sdk]
10.0.203 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.7 [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:
DOTNET_CLI_UI_LANGUAGE [en-US]

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Visual Studio Code Extensions
Extension Author Version Folder Name
black-formatter ms-python 2026.4.0 ms-python.black-formatter-2026.4.0
cmake twxs 0.0.17 twxs.cmake-0.0.17
cmake-tools ms-vscode 1.23.52 ms-vscode.cmake-tools-1.23.52
cpp-devtools ms-vscode 0.5.13 ms-vscode.cpp-devtools-0.5.13
cpptools ms-vscode 1.32.2 ms-vscode.cpptools-1.32.2-win32-x64
cpptools-extension-pack ms-vscode 1.5.1 ms-vscode.cpptools-extension-pack-1.5.1
cpptools-themes ms-vscode 2.0.0 ms-vscode.cpptools-themes-2.0.0
csharp ms-dotnettools 2.130.5 ms-dotnettools.csharp-2.130.5-win32-x64
debugpy ms-python 2026.6.0 ms-python.debugpy-2026.6.0-win32-x64
intellicode-api-usage-examples VisualStudioExptTeam 0.2.9 visualstudioexptteam.intellicode-api-usage-examples-0.2.9
java redhat 1.54.0 redhat.java-1.54.0-win32-x64
python ms-python 2026.4.0 ms-python.python-2026.4.0-win32-x64
vscode-antlr4 mike-lischke 2.4.7 mike-lischke.vscode-antlr4-2.4.7
vscode-dotnet-runtime ms-dotnettools 3.0.0 ms-dotnettools.vscode-dotnet-runtime-3.0.0
vscode-gradle vscjava 3.17.3 vscjava.vscode-gradle-3.17.3
vscode-java-debug vscjava 0.59.0 vscjava.vscode-java-debug-0.59.0
vscode-java-dependency vscjava 0.27.2 vscjava.vscode-java-dependency-0.27.2
vscode-java-pack vscjava 0.30.5 vscjava.vscode-java-pack-0.30.5
vscode-java-test vscjava 0.45.0 vscjava.vscode-java-test-0.45.0
vscode-maven vscjava 0.45.3 vscjava.vscode-maven-0.45.3
vscode-pylance ms-python 2026.2.1 ms-python.vscode-pylance-2026.2.1
vscode-python-envs ms-python 1.28.0 ms-python.vscode-python-envs-1.28.0-win32-x64
vscode-speech ms-vscode 0.16.0 ms-vscode.vscode-speech-0.16.0-win32-x64
vscodeintellicode VisualStudioExptTeam 1.3.2 visualstudioexptteam.vscodeintellicode-1.3.2
C# Settings
Setting Value
preferCSharpExtension false
compilerDiagnosticScope openFiles
analyzerDiagnosticScope openFiles
enableXamlTools true
useServerGC true
System Info
Item Value
CPUs Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz (12 x 3192)
GPU Status 2d_canvas: enabled
GPU0: VENDOR= 0x10de, DEVICE=0x1f02 [NVIDIA GeForce RTX 2070], DRIVER_VENDOR=NVIDIA, DRIVER_VERSION=27.21.14.5671 ACTIVE
GPU1: VENDOR= 0x1414, DEVICE=0x008c [Microsoft Basic Render Driver], DRIVER_VERSION=10.0.26100.8246
Machine model name:
Machine model version:
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
trees_in_viz: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 31.93GB (18.95GB free)
Process Argv --crash-reporter-id e410d60b-c196-4fda-9bf0-3429e57343ac
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vswsl492:30256859
binariesv615:30325510
nativeloc1:31344060
dwcopilot:31170013
dwoutputs:31242946
copilot_t_ci:31333650
e5gg6876:31282496
pythonrdcb7:31342333
6518g693:31463988
aj953862:31281341
63221493:31336333
envsdeactivate2:31505458
cloudbuttont:31379625
3efgi100_wstrepl:31403338
839jf696:31457053
ec5jj548:31422691
cp_cls_t_966_ss:31454198
inlinechat_v2_hd992725:31505030
4je02754:31466945
8hhj4413:31478653
cp_cls_c_1081:31454833
conptydll_true:31498968
e9c30283:31461165
test_treatment2:31471001
46204921:31447328
idci7584:31464702
e3e4d672:31494082
ei9d7968:31496641
chat:31457767
7e187181:31503455
ghj88844:31499326
h08i8180:31475369
23c7c724:31491644
client_tst_t:31495907
ddid_t:31478206
getcmakediagnosticsoff:31489825
7df3h592:31507015
cp_cls_c_1082:31504161
logging_enabled_new:31498466
db5d2638:31499441
748c7209:31497895
32d76977:31505232
539gd155_c:31506875

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions