Skip to content

Document is null when it was required for textDocument/documentSymbol #9205

@advgiraffe

Description

@advgiraffe

Type: Bug

Issue Description

Error pops up "Request textDocument/definition failed." from C# extension

Steps to Reproduce

It just happens in the background. I assume an issue with some recent code change - like a csproj file? It just happens from time to time.

Expected Behavior

Don't raise the error because you handle whatever condtion this is

Actual Behavior

Error toast as described above.

Extension version: 2.130.5
VS Code version: Code 1.116.0 (560a9dba96f961efea7b1612916f89e5d5d4d679, 2026-04-15T00:28:13Z)
OS version: Windows_NT x64 10.0.26200
Modes:

Logs

C# log

Details
2026-04-19 15:41:59.626 [info] Locating .NET runtime version 10.0.5
2026-04-19 15:42:01.110 [info] Dotnet path: c:\Users\eriks\AppData\Roaming\Code\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime\.dotnet\10.0.5~x64~aspnetcore\dotnet.exe
2026-04-19 15:42:01.110 [info] Activating C# + C# Dev Kit...
2026-04-19 15:42:01.356 [info] info: Program[0]
2026-04-19 15:42:01.356 [info]       Server started with process ID 41220
2026-04-19 15:42:02.930 [info] [Program] Language server initialized
2026-04-19 15:42:02.931 [info] [Program] Monitoring client process 33904 for exit
2026-04-19 15:42:03.719 [error] [textDocument/documentSymbol] [LSP] System.ArgumentNullException: Value cannot be null. (Parameter 'Document is null when it was required for textDocument/documentSymbol')
   at Microsoft.CodeAnalysis.LanguageServer.Handler.RequestContext.GetRequiredDocument() in /_/src/LanguageServer/Protocol/Handler/RequestContext.cs:line 211
   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentSymbolsHandler.HandleRequestAsync(RoslynDocumentSymbolParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Handler/Symbols/DocumentSymbolsHandler.cs:line 35
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`1.StartRequestAsync[TRequest,TResponse](TRequest request, TRequestContext context, IMethodHandler handler, String language, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 192
2026-04-19 15:42:03.719 [error] [textDocument/documentSymbol] [LSP] System.ArgumentNullException: Value cannot be null. (Parameter 'Document is null when it was required for textDocument/documentSymbol')
   at Microsoft.CodeAnalysis.LanguageServer.Handler.RequestContext.GetRequiredDocument() in /_/src/LanguageServer/Protocol/Handler/RequestContext.cs:line 211
   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentSymbolsHandler.HandleRequestAsync(RoslynDocumentSymbolParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Handler/Symbols/DocumentSymbolsHandler.cs:line 35
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`1.StartRequestAsync[TRequest,TResponse](TRequest request, TRequestContext context, IMethodHandler handler, String language, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 192
2026-04-19 15:42:03.727 [error] Request textDocument/documentSymbol failed.
  Message: Value cannot be null. (Parameter 'Document is null when it was required for textDocument/documentSymbol')
  Code: -32000 
[object Object]
2026-04-19 15:42:03.729 [error] Request textDocument/documentSymbol failed.
  Message: Value cannot be null. (Parameter 'Document is null when it was required for textDocument/documentSymbol')
  Code: -32000 
[object Object]
2026-04-19 15:42:06.516 [info] [textDocument/semanticTokens/range] [Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager] .NET BuildHost started from c:\Users\eriks\.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-04-19 15:42:06.550 [warning] [textDocument/semanticTokens/range] [LanguageServerProjectLoader] Project C:\Users\eriks\AppData\Local\Temp\roslyn-canonical-misc\1883e35b-b3b9-41c5-a114-4fbaa1275f59\Canonical.csproj has unresolved dependencies
2026-04-19 15:42:06.971 [info] [textDocument/semanticTokens/range] [LanguageServerProjectLoader] Successfully completed load of C:\Users\eriks\AppData\Local\Temp\roslyn-canonical-misc\1883e35b-b3b9-41c5-a114-4fbaa1275f59\Canonical.cs
2026-04-19 15:42:07.075 [info] [textDocument/semanticTokens/range] [LanguageServerProjectLoader] Restoring Canonical.cs: Running dotnet restore on C:\Users\eriks\AppData\Local\Temp\roslyn-canonical-misc\1883e35b-b3b9-41c5-a114-4fbaa1275f59\Canonical.cs
2026-04-19 15:42:07.080 [info] [textDocument/semanticTokens/range] [Microsoft.CodeAnalysis.LanguageServer.DotnetCliHelper] Using dotnet executable configured on the PATH
2026-04-19 15:42:08.143 [info] [textDocument/semanticTokens/range] [LanguageServerProjectLoader] Restoring Canonical.cs:   Determining projects to restore...
2026-04-19 15:42:08.612 [info] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\source\TradeTrack2\src\PortfolioAnalyzer.Analysis\PortfolioAnalyzer.Analysis.csproj loaded by C# Dev Kit
2026-04-19 15:42:08.636 [info] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\source\TradeTrack2\src\PortfolioAnalyzer.QuoteService\PortfolioAnalyzer.QuoteService.csproj loaded by C# Dev Kit
2026-04-19 15:42:08.640 [info] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\source\TradeTrack2\tests\PortfolioAnalyzer.Analysis.Tests\PortfolioAnalyzer.Analysis.Tests.csproj loaded by C# Dev Kit
2026-04-19 15:42:08.644 [info] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\source\TradeTrack2\src\PortfolioAnalyzer.Web\PortfolioAnalyzer.Web.csproj loaded by C# Dev Kit
2026-04-19 15:42:08.646 [info] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\source\TradeTrack2\tests\PortfolioAnalyzer.Domain.Tests\PortfolioAnalyzer.Domain.Tests.csproj loaded by C# Dev Kit
2026-04-19 15:42:08.650 [info] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\source\TradeTrack2\tests\PortfolioAnalyzer.QuoteService.Tests\PortfolioAnalyzer.QuoteService.Tests.csproj loaded by C# Dev Kit
2026-04-19 15:42:08.652 [info] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\source\TradeTrack2\src\PortfolioAnalyzer.Infrastructure\PortfolioAnalyzer.Infrastructure.csproj loaded by C# Dev Kit
2026-04-19 15:42:08.655 [info] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\source\TradeTrack2\src\PortfolioAnalyzer.Domain\PortfolioAnalyzer.Domain.csproj loaded by C# Dev Kit
2026-04-19 15:42:08.656 [info] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\source\TradeTrack2\tests\PortfolioAnalyzer.Infrastructure.Tests\PortfolioAnalyzer.Infrastructure.Tests.csproj loaded by C# Dev Kit
2026-04-19 15:42:08.659 [info] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\source\TradeTrack2\tests\PortfolioAnalyzer.Application.Tests\PortfolioAnalyzer.Application.Tests.csproj loaded by C# Dev Kit
2026-04-19 15:42:08.662 [info] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\source\TradeTrack2\src\PortfolioAnalyzer.Application\PortfolioAnalyzer.Application.csproj loaded by C# Dev Kit
2026-04-19 15:42:08.665 [info] [serviceBroker/connect] [WorkspaceProjectFactoryService] Project D:\source\TradeTrack2\tests\PortfolioAnalyzer.Integration.Tests\PortfolioAnalyzer.Integration.Tests.csproj loaded by C# Dev Kit
2026-04-19 15:42:09.105 [info] [textDocument/semanticTokens/range] [LanguageServerProjectLoader] Restoring Canonical.cs:   Restored C:\Users\eriks\AppData\Local\Temp\roslyn-canonical-misc\1883e35b-b3b9-41c5-a114-4fbaa1275f59\Canonical.csproj (in 610 ms).
2026-04-19 15:42:09.183 [info] [textDocument/semanticTokens/range] [LanguageServerProjectLoader] Restore complete
2026-04-19 15:42:09.184 [info] [textDocument/semanticTokens/range] [LanguageServerProjectLoader] Completed (re)load of all projects in 00:00:04.5303058
2026-04-19 16:02:36.569 [error] [textDocument/definition] [LSP] System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'position')
   at Microsoft.CodeAnalysis.Text.CompositeText.CompositeTextLineInfo.IndexOf(Int32 position) in /_/src/Compilers/Core/Portable/Text/CompositeText.cs:line 475
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetLineFromPosition(Int32 position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 40
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetLinePosition(Int32 position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 48
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.TextSpanToRange(TextSpan textSpan, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 381
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.<TextSpanToLocationAsync>g__ConvertTextSpanWithTextToLocation|34_1(TextSpan span, SourceText text, DocumentUri documentUri) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 605
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.<TextSpanToLocationAsync>g__ConvertTextSpanToLocationAsync|34_0(TextDocument document, TextSpan span, Boolean isStale, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 600
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.TextSpanToLocationAsync(TextDocument document, TextSpan textSpan, Boolean isStale, Nullable`1 context, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 579
   at Microsoft.CodeAnalysis.LanguageServer.Handler.AbstractGoToDefinitionHandler.GetDefinitionsAsync(IGlobalOptionService globalOptions, IMetadataAsSourceFileService metadataAsSourceFileService, Workspace workspace, Document document, Boolean forSymbolType, LinePosition linePosition, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs:line 67
   at Microsoft.CodeAnalysis.LanguageServer.Handler.AbstractGoToDefinitionHandler.GetDefinitionAsync(TextDocumentPositionParams request, Boolean forSymbolType, RequestContext context, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs:line 47
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`1.StartRequestAsync[TRequest,TResponse](TRequest request, TRequestContext context, IMethodHandler handler, String language, CancellationToken cancellationToken)
2026-04-19 16:02:36.570 [error] Request textDocument/definition failed.
  Message: Specified argument was out of the range of valid values. (Parameter 'position')
  Code: -32000 
[object Object]
2026-04-19 16:02:36.713 [error] [textDocument/definition] [LSP] System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'position')
   at Microsoft.CodeAnalysis.Text.CompositeText.CompositeTextLineInfo.IndexOf(Int32 position) in /_/src/Compilers/Core/Portable/Text/CompositeText.cs:line 475
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetLineFromPosition(Int32 position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 40
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetLinePosition(Int32 position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 48
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.TextSpanToRange(TextSpan textSpan, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 381
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.<TextSpanToLocationAsync>g__ConvertTextSpanWithTextToLocation|34_1(TextSpan span, SourceText text, DocumentUri documentUri) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 605
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.<TextSpanToLocationAsync>g__ConvertTextSpanToLocationAsync|34_0(TextDocument document, TextSpan span, Boolean isStale, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 600
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.TextSpanToLocationAsync(TextDocument document, TextSpan textSpan, Boolean isStale, Nullable`1 context, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 579
   at Microsoft.CodeAnalysis.LanguageServer.Handler.AbstractGoToDefinitionHandler.GetDefinitionsAsync(IGlobalOptionService globalOptions, IMetadataAsSourceFileService metadataAsSourceFileService, Workspace workspace, Document document, Boolean forSymbolType, LinePosition linePosition, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs:line 67
   at Microsoft.CodeAnalysis.LanguageServer.Handler.AbstractGoToDefinitionHandler.GetDefinitionAsync(TextDocumentPositionParams request, Boolean forSymbolType, RequestContext context, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs:line 47
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`1.StartRequestAsync[TRequest,TResponse](TRequest request, TRequestContext context, IMethodHandler handler, String language, CancellationToken cancellationToken)
2026-04-19 16:02:36.714 [error] Request textDocument/definition failed.
  Message: Specified argument was out of the range of valid values. (Parameter 'position')
  Code: -32000 
[object Object]

C# LSP Trace Logs log

Details

Environment Information

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

Dotnet Information

Host:
Version: 10.0.5
Architecture: x64
Commit: a612c2a105
RID: win-x64

.NET SDKs installed:
No SDKs were found.

.NET runtimes installed:
Microsoft.AspNetCore.App 10.0.5 [c:\Users\eriks\AppData\Roaming\Code\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime.dotnet\10.0.5x64aspnetcore\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 10.0.5 [c:\Users\eriks\AppData\Roaming\Code\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime.dotnet\10.0.5x64aspnetcore\shared\Microsoft.NETCore.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]
DOTNET_MULTILEVEL_LOOKUP [0]
DOTNET_NOLOGO [true]

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
claude-code Anthropic 2.1.114 anthropic.claude-code-2.1.114-win32-x64
cmake twxs 0.0.17 twxs.cmake-0.0.17
cpptools ms-vscode 1.31.4 ms-vscode.cpptools-1.31.4-win32-x64
csdevkit ms-dotnettools 3.10.14 ms-dotnettools.csdevkit-3.10.14-win32-x64
csharp ms-dotnettools 2.130.5 ms-dotnettools.csharp-2.130.5-win32-x64
debugpy ms-python 2025.18.0 ms-python.debugpy-2025.18.0-win32-x64
jupyter-keymap ms-toolsai 1.1.2 ms-toolsai.jupyter-keymap-1.1.2
pdf tomoki1207 1.2.2 tomoki1207.pdf-1.2.2
plantuml jebbs 2.18.1 jebbs.plantuml-2.18.1
platformio-ide platformio 3.3.4 platformio.platformio-ide-3.3.4-win32-x64
powershell ms-vscode 2025.4.0 ms-vscode.powershell-2025.4.0
python ms-python 2026.4.0 ms-python.python-2026.4.0-win32-x64
rainbow-csv mechatroner 3.24.1 mechatroner.rainbow-csv-3.24.1
remote-wsl ms-vscode-remote 0.104.3 ms-vscode-remote.remote-wsl-0.104.3
teleplot alexnesnes 1.1.4 alexnesnes.teleplot-1.1.4
vscode-containers ms-azuretools 2.4.1 ms-azuretools.vscode-containers-2.4.1
vscode-dotnet-runtime ms-dotnettools 3.0.0 ms-dotnettools.vscode-dotnet-runtime-3.0.0
vscode-icons vscode-icons-team 12.18.0 vscode-icons-team.vscode-icons-12.18.0
vscode-pull-request-github GitHub 0.136.0 github.vscode-pull-request-github-0.136.0
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
C# Settings
Setting Value
preferCSharpExtension false
compilerDiagnosticScope openFiles
analyzerDiagnosticScope openFiles
enableXamlTools true
useServerGC true
System Info
Item Value
CPUs 12th Gen Intel(R) Core(TM) i7-12700H (20 x 2688)
GPU Status 2d_canvas: enabled
GPU0: VENDOR= 0x8086, DEVICE=0x46a6 [Intel(R) Iris(R) Xe Graphics], DRIVER_VENDOR=Intel, DRIVER_VERSION=32.0.101.6790 ACTIVE
GPU1: VENDOR= 0x10de, DEVICE=0x2860 [NVIDIA GeForce RTX 4070 Laptop GPU], DRIVER_VERSION=32.0.15.9597
GPU2: 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) 63.64GB (34.61GB free)
Process Argv --crash-reporter-id f8f119ef-42a4-4ea4-be47-0c264931ed67
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vswsl492cf:30256860
binariesv615:30325510
nativeloc1:31344060
dwcopilot:31170013
dwoutputs:31242946
copilot_t_ci:31333650
e5gg6876:31282496
pythonrdcb7:31342333
6518g693:31463988
aj953862:31281341
4f60g487:31327383
6abeh943:31336334
envsdeactivate2:31464701
cloudbuttont:31379625
3efgi100_wstrepl:31403338
use-responses-api:31390855
je187915:31401257
ec5jj548:31422691
cmp-cht-control-jan-release-cp:31489981
cp_cls_t_966_ss:31454198
4je02754:31466945
8hhj4413:31478653
ge8j1254_inline_auto_hint_haiku:31490510
38bie571_auto:31478678
cp_cls_t_1081:31454832
conptydll_true:31489736
ia-use-proxy-models-svc:31452481
e9c30283:31461165
test_treatment2:31471001
xe_6dc23131:31497330
idci7584:31464702
e3e4d672:31494082
ei9d7968:31496641
534a6447:31496642
nes-extended-on:31455476
chat:31457767
8hig5102:31480529
sonnet46_4g7d3299:31495258
67jbj424:31495046
cpptoolson-v2:31475363
i2gc6536:31494041
30450953:31494756
ghj88844:31492074
ec1eg703:31491645
client_tst_t:31495907
po_split_t:31488386
ddid_t:31478206
getcmakediagnosticson:31489824
ja75b849:31495667
nes-perm-reb-0:31490411
pro_conc_t:31492543
cp_cls_c_1082:31491634
719di409_sum_t:31495624
logging_disabled_new:31493366
j0d79568:31494311
output_3x:31496636
56dj4588:31497896

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