Skip to content

Problem opening *.razor files #8359

@webreidi

Description

@webreidi

Type: Bug

Issue Description

Steps to Reproduce

Open workspace that contains a blazor app.
Open a .razor file in the editor.

Expected Behavior

No errors and I can continue to work with my solution.

Actual Behavior

Error opening *.razor file and the LSP crashes.

Logs

2025-06-11 14:15:03.524 [info] [Error - 2:15:03 PM] [textDocument/didChange] [LSP] System.ArgumentException: Range={ Start={ Line=34, Character=44 }, End={ Line=35, Character=26 } }. text.Length=2374. text.Lines.Count=93
---> System.ArgumentOutOfRangeException: 'end' must not be less than 'start'. start='938' end='929'. (Parameter 'end')
at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in //src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 322
--- End of inner exception stack trace ---
at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /
/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 327
at System.Collections.Immutable.ImmutableArray1.Builder.AddRange(IEnumerable1 items)
at Roslyn.Utilities.EnumerableExtensions.SelectAsArray[TSource,TResult](IEnumerable1 source, Func2 selector) in //src/Dependencies/Collections/Extensions/IEnumerableExtensions.cs:line 286
at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.GetUpdatedSourceText(TextDocumentContentChangeEvent[] contentChanges, SourceText text) in /
/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 70
at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.HandleRequestAsync(DidChangeTextDocumentParams request, RequestContext context, CancellationToken cancellationToken) in //src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 33
at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem1.StartRequestAsync[TRequest,TResponse](TRequest request, TRequestContext context, IMethodHandler handler, String language, CancellationToken cancellationToken) 2025-06-11 14:15:03.528 [info] [Error - 2:15:03 PM] [LSP] System.ArgumentException: Range={ Start={ Line=34, Character=44 }, End={ Line=35, Character=26 } }. text.Length=2374. text.Lines.Count=93 ---> System.ArgumentOutOfRangeException: 'end' must not be less than 'start'. start='938' end='929'. (Parameter 'end') at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 322 --- End of inner exception stack trace --- at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 327 at System.Collections.Immutable.ImmutableArray1.Builder.AddRange(IEnumerable1 items) at Roslyn.Utilities.EnumerableExtensions.SelectAsArray[TSource,TResult](IEnumerable1 source, Func2 selector) in /_/src/Dependencies/Collections/Extensions/IEnumerableExtensions.cs:line 286 at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.GetUpdatedSourceText(TextDocumentContentChangeEvent[] contentChanges, SourceText text) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 70 at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.HandleRequestAsync(DidChangeTextDocumentParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 33 at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem1.StartRequestAsync[TRequest,TResponse](TRequest request, TRequestContext context, IMethodHandler handler, String language, CancellationToken cancellationToken)
at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem1.StartRequestAsync[TRequest,TResponse](TRequest request, TRequestContext context, IMethodHandler handler, String language, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 246 at Microsoft.CodeAnalysis.LanguageServer.RoslynRequestExecutionQueue.WrapStartRequestTaskAsync(Task requestTask, Boolean rethrowExceptions) in /_/src/LanguageServer/Protocol/RoslynRequestExecutionQueue.cs:line 32 at Microsoft.CommonLanguageServerProtocol.Framework.RequestExecutionQueue1.ProcessQueueCoreAsync[TRequest,TResponse](IQueueItem1 work, IMethodHandler handler, RequestHandlerMetadata metadata, ConcurrentDictionary2 concurrentlyExecutingTasks, CancellationTokenSource currentWorkCts, CancellationToken cancellationToken) in /
/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/RequestExecutionQueue.cs:line 369
at Microsoft.CommonLanguageServerProtocol.Framework.RequestExecutionQueue1.InvokeProcessCoreAsync(IQueueItem1 work, RequestHandlerMetadata metadata, IMethodHandler handler, MethodInfo methodInfo, ConcurrentDictionary2 concurrentlyExecutingTasks, CancellationTokenSource currentWorkCts, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/RequestExecutionQueue.cs:line 322 at Microsoft.CommonLanguageServerProtocol.Framework.RequestExecutionQueue1.ProcessQueueAsync() in /_/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/RequestExecutionQueue.cs:line 274
2025-06-11 14:15:03.530 [info] [Info - 2:15:03 PM] [LSP] Error processing queue, shutting down
2025-06-11 14:15:03.539 [info] [Info - 2:15:03 PM] Error processing queue, shutting down
2025-06-11 14:15:03.548 [info] [Error - 2:15:03 PM] Request textDocument/diagnostic failed.
2025-06-11 14:15:03.548 [info] Message: Server was requested to shut down.
Code: -32000
[object Object]
2025-06-11 14:15:03.549 [info] [Error - 2:15:03 PM] Document pull failed for text document file:///c%3A/Users/webreidi/source/repos/MyTodoListApp/MyNewTodoListApp/Pages/Todo.razor
2025-06-11 14:15:03.549 [info] Message: Server was requested to shut down.
Code: -32000
[object Object]

...
2025-06-11 14:15:14.562 [info] [Error - 2:15:14 PM] Document pull failed for text document file:///c%3A/Users/webreidi/source/repos/MyTodoListApp/MyNewTodoListApp/Pages/Todo.razor
2025-06-11 14:15:14.562 [info] Message: Expected 'Path.GetDirectoryName(razorDocument.Project.FilePath)' to be non-null.
File='/_/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/TextDocumentExtensions.cs', Line=28
Code: -32000
[object Object]

...

2025-06-11 14:15:20.307 [info] [Error - 2:15:20 PM] [textDocument/diagnostic] [LanguageServerProjectLoader] Error while loading c:\Users\webreidi\source\repos\MyTodoListApp\MyNewTodoListApp\Pages\Todo.razor: Exception thrown: System.InvalidOperationException: The solution does not contain the specified document.
at Microsoft.CodeAnalysis.Shared.Extensions.ISolutionExtensions.GetRequiredDocument(Solution solution, DocumentId documentId) in //src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ISolutionExtensions.cs:line 64
at Microsoft.CodeAnalysis.Workspace.g__UpdateAddedDocumentToExistingContentsInSolution|29_1(Solution solution, ArrayBuilder1 addedDocumentIds) in /_/src/Workspaces/Core/Portable/Workspace/Workspace.cs:line 351 at Microsoft.CodeAnalysis.Workspace.<SetCurrentSolutionAsync>g__UnifyLinkedDocumentContents|29_0(Solution oldSolution, Solution newSolution) in /_/src/Workspaces/Core/Portable/Workspace/Workspace.cs:line 325 at Microsoft.CodeAnalysis.Workspace.SetCurrentSolutionAsync[TData](Boolean useAsync, TData data, Func3 transformation, Boolean mayRaiseEvents, Action3 onBeforeUpdate, Action3 onAfterUpdate, CancellationToken cancellationToken) in /
/src/Workspaces/Core/Portable/Workspace/Workspace.cs:line 523
at Microsoft.CodeAnalysis.Workspace.SetCurrentSolutionAsync(Boolean useAsync, Func2 transformation, Func3 changeKind, Action2 onBeforeUpdate, Action2 onAfterUpdate, CancellationToken cancellationToken) in //src/Workspaces/Core/Portable/Workspace/Workspace.cs:line 257
at Microsoft.CodeAnalysis.Workspaces.ProjectSystem.ProjectSystemProjectFactory.ApplyBatchChangeToWorkspaceMaybe_NoLockAsync(Boolean useAsync, Func3 mutation, Action1 onAfterUpdateAlways) in /
/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProjectFactory.cs:line 317
at Microsoft.CodeAnalysis.Workspaces.ProjectSystem.ProjectSystemProjectFactory.ApplyBatchChangeToWorkspaceMaybeAsync(Boolean useAsync, Func3 mutation, Action1 onAfterUpdateAlways) in //src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProjectFactory.cs:line 293
at Microsoft.CodeAnalysis.Workspaces.ProjectSystem.ProjectSystemProject.OnBatchScopeDisposedMaybeAsync(Boolean useAsync) in /
/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.cs:line 597
at Microsoft.CodeAnalysis.Workspaces.ProjectSystem.ProjectSystemProject.BatchScope.DisposeAsync() in //src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.cs:line 566
at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.UpdateWithNewProjectInfoAsync(ProjectFileInfo newProjectInfo, Boolean hasAllInformation, ILogger logger) in /
/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 244
at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectLoader.ReloadProjectAsync(ProjectToLoad projectToLoad, ToastErrorReporter toastErrorReporter, BuildHostProcessManager buildHostProcessManager, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectLoader.cs:line 258

C# log

Post the output from Output-->C# here

C# LSP Trace Logs

Post the output from Output-->C# LSP Trace Logs here. Requires the `C#` output window log level to be set to `Trace`

Environment information

VSCode version: 1.101.0-insider
C# Extension: 2.82.12
Using OmniSharp: false

Dotnet Information .NET SDK: Version: 9.0.300 Commit: 15606fe0a8 Workload version: 9.0.300-manifests.1f3f9d5d MSBuild version: 17.14.5+edd3bbf37

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

.NET workloads installed:
[android]
Installation Source: SDK 9.0.300, VS 17.14.36202.13
Manifest Version: 35.0.61/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.android\35.0.61\WorkloadManifest.json
Install Type: Msi

[aspire]
Installation Source: SDK 9.0.300, VS 17.14.36202.13
Manifest Version: 8.2.2/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
Install Type: Msi

[ios]
Installation Source: SDK 9.0.300, VS 17.14.36202.13
Manifest Version: 18.4.9291/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.ios\18.4.9291\WorkloadManifest.json
Install Type: Msi

[maccatalyst]
Installation Source: SDK 9.0.300, VS 17.14.36202.13
Manifest Version: 18.4.9291/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maccatalyst\18.4.9291\WorkloadManifest.json
Install Type: Msi

[maui-windows]
Installation Source: SDK 9.0.300, VS 17.14.36202.13
Manifest Version: 9.0.51/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maui\9.0.51\WorkloadManifest.json
Install Type: Msi

Configured to use loose manifests when installing new manifests.

Host:
Version: 9.0.5
Architecture: x64
Commit: e36e4d1a8f

.NET SDKs installed:
7.0.410 [C:\Program Files\dotnet\sdk]
8.0.312 [C:\Program Files\dotnet\sdk]
8.0.409 [C:\Program Files\dotnet\sdk]
9.0.106 [C:\Program Files\dotnet\sdk]
9.0.204 [C:\Program Files\dotnet\sdk]
9.0.300 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.5 [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
Extension Author Version Folder Name
azure-dev ms-azuretools 0.9.0 ms-azuretools.azure-dev-0.9.0
copilot GitHub 1.332.1619 github.copilot-1.332.1619
copilot-chat GitHub 0.28.2025061002 github.copilot-chat-0.28.2025061002
csdevkit ms-dotnettools 1.30.13 ms-dotnettools.csdevkit-1.30.13-win32-x64
csharp ms-dotnettools 2.82.12 ms-dotnettools.csharp-2.82.12-win32-x64
dotnet-maui ms-dotnettools 1.10.16 ms-dotnettools.dotnet-maui-1.10.16-win32-x64
gitlens eamodio 2025.6.1105 eamodio.gitlens-2025.6.1105
msbuild-editor mhutch 2.9.676-g4bd136a1f0 mhutch.msbuild-editor-2.9.676-g4bd136a1f0
remote-containers ms-vscode-remote 0.416.0 ms-vscode-remote.remote-containers-0.416.0
test-adapter-converter ms-vscode 0.2.1 ms-vscode.test-adapter-converter-0.2.1
vscode-ai-foundry TeamsDevApp 0.6.0 teamsdevapp.vscode-ai-foundry-0.6.0
vscode-azure-github-copilot ms-azuretools 1.0.26 ms-azuretools.vscode-azure-github-copilot-1.0.26-win32-x64
vscode-azureresourcegroups ms-azuretools 0.10.12 ms-azuretools.vscode-azureresourcegroups-0.10.12
vscode-dotnet-runtime ms-dotnettools 2.3.5 ms-dotnettools.vscode-dotnet-runtime-2.3.5
vscode-learncloud azurepaas-tools 0.8.0 azurepaas-tools.vscode-learncloud-0.8.0
vscode-yaml redhat 1.18.0 redhat.vscode-yaml-1.18.0
windows-ai-studio ms-windows-ai-studio 0.14.3 ms-windows-ai-studio.windows-ai-studio-0.14.3-win32-x64

Extension version: 2.82.12
VS Code version: Code - Insiders 1.101.0-insider (e22bab12c80837105807642c18292cdd3f19691f, 2025-06-10T18:50:37.502Z)
OS version: Windows_NT x64 10.0.26120
Modes:

System Info
Item Value
CPUs Intel(R) Core(TM) Ultra 7 165H (22 x 3072)
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.64GB (1.71GB free)
Process Argv --crash-reporter-id df9569b1-4056-47ee-b1a6-521ad1c587e3
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyt551cf:31249598
vscod805:30301674
c4g48928:30535728
962ge761:30841072
dsvsc014:30777825
dsvsc015:30821418
h48ei257:31000450
pythontbext0:30879054
cppperfnew:30980852
dwnewjupytercf:31046870
pythonrstrctxt:31093868
nativeloc1:31118317
e80f6927:31120813
dwcopilot:31158714
c3hdf307:31184662
6074i472:31201624
dwoutputs:31242946
customenabled:31248079
hdaa2157:31222309
copilot_t_ci:31222730
g012b348:31231168
pythoneinst12:31251391
bgtreat:31252123
c7cif404:31309980
pythonpulldiag:31287486
6gi0g917:31259950
editoredits36407:31282444
996jf627:31264550
pythonrdcb7:31268811
usemplatestapi:31297334
e6194696:31317039
747dc170:31275146
pythonfullctx:31296836
6518g693:31302842
pylancecolor:31288664
generatesymbolt:31280541
convertfstringf:31280702
gendocf:31280703
nes6j6d6965:31321961
923gi514:31310909
b99bg931:31306656
fd45d811:31320948
convertlamdat:31319677
gce3e431:31315077

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions