vscode-csharp: Formatting Razor File errors with "Request textDocument/formatting failed"

Issue Description

When I try to format a Razor file, the formatting fails and I see an error.

Steps to Reproduce

  • Create a .cshtml file
  • Add some markup (can be simple HTML)
  • Format the document (either alt+shift+f or format on save)

Expected Behavior

The document is formatted and there are no errors

Actual Behavior

The document does not format and VS Code displays an error

https://user-images.githubusercontent.com/1382768/214971355-d141d099-5863-4ee6-b882-08e327faca74.mp4

Logs

OmniSharp log

No errors

C# log

No errors

Razor Log

[Error - 6:07:07 PM] [null]
[Error - 6:07:07 PM] Request textDocument/formatting failed.
  Message: Specified argument was out of the range of valid values. (Parameter 'Range start line 3 matches or exceeds SourceText boundary 3.')
  Code: -32000 
[object Object]

Environment information

VSCode version: 1.74.3 C# Extension: 1.25.4

Dotnet Information .NET SDK: Version: 7.0.102 Commit: 4bbdd14480

Runtime Environment: OS Name: Windows OS Version: 10.0.19045 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.102\

Host: Version: 7.0.2 Architecture: x64 Commit: d037e070eb

.NET SDKs installed: 3.0.100 [C:\Program Files\dotnet\sdk] 3.1.426 [C:\Program Files\dotnet\sdk] 5.0.408 [C:\Program Files\dotnet\sdk] 6.0.100 [C:\Program Files\dotnet\sdk] 6.0.201 [C:\Program Files\dotnet\sdk] 6.0.302 [C:\Program Files\dotnet\sdk] 6.0.308 [C:\Program Files\dotnet\sdk] 6.0.403 [C:\Program Files\dotnet\sdk] 6.0.405 [C:\Program Files\dotnet\sdk] 7.0.102 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.2 [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
azure-account ms-vscode 0.11.3
azure-pipelines ms-azure-devops 1.208.0
carbon-now-sh ericadamski 1.2.0
csharp ms-dotnettools 1.25.4
docomment k–kato 0.1.32
dotnet-test-explorer formulahendry 0.7.8
EditorConfig EditorConfig 0.16.4
githistory donjayamanne 0.6.19
gitlens eamodio 13.2.0
graphql-for-vscode kumar-harsh 1.15.3
intellicode-api-usage-examples VisualStudioExptTeam 0.2.7
lit-html bierner 1.11.1
LiveServer ritwickdey 5.7.9
markdown-preview-github-styles bierner 1.0.1
mermaid-markdown-syntax-highlighting bpruitt-goddard 1.5.0
nunjucks ronnidc 0.3.1
postcss csstools 1.0.9
powershell ms-vscode 2023.1.0
prettier-vscode esbenp 9.10.4
remote-wsl ms-vscode-remote 0.72.0
test-adapter-converter ms-vscode 0.1.6
user-secrets adrianwilczynski 2.0.1
volar Vue 1.0.24
vscode-azureresourcegroups ms-azuretools 0.5.6
vscode-docker ms-azuretools 1.23.3
vscode-drawio hediet 1.6.6
vscode-eslint dbaeumer 2.2.6
vscode-filesize mkxml 3.1.0
vscode-icons vscode-icons-team 12.2.0
vscode-less mrmlnc 0.6.3
vscode-markdownlint DavidAnson 0.49.0
vscode-mermaid-preview vstirbu 1.6.3
vscode-mysql formulahendry 0.4.1
vscode-scss mrmlnc 0.10.0
vscode-sqlite alexcvzz 0.14.1
vscode-stylelint stylelint 1.2.3
vscode-tailwindcss bradlc 0.9.6
vscode-versionlens pflannery 1.0.14
vscode-xml redhat 0.23.0
vscodeintellicode VisualStudioExptTeam 1.2.30
vsliveshare ms-vsliveshare 1.0.5823

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 36
  • Comments: 46 (10 by maintainers)

Commits related to this issue

Most upvoted comments

This happens with every edit of a .cshtml file. C# extension 2.0.357

Version: 1.81.0 (Universal) Commit: 6445d93c81ebe42c4cbd7a60712e0b17d9463e97 Date: 2023-08-02T12:40:02.782Z (1 wk ago) Electron: 22.3.18 ElectronBuildId: 22689846 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Darwin arm64 22.5.0

<TargetFramework>net6.0</TargetFramework>

dotnet --list-sdks 6.0.100 [/usr/local/share/dotnet/sdk] 6.0.412 [/usr/local/share/dotnet/sdk]

Entering method textDocument/formatting. [Error - 11:37:45 AM] [null] [Error - 11:37:45 AM] Request textDocument/formatting failed. Message: Specified argument was out of the range of valid values. (Parameter ‘Range end line 65 matches or exceeds SourceText boundary 65.’) Code: -32000 [object Object] Entering method textDocument/didSave. [Info - 11:37:45 AM] Saved Document

It is super annoying…
Any / all recommendations welcome.

Can confirm that downgrading to C# extension v1.25.2 fixes this for now. dotnet 6.0.300 and VSCode:

Version: 1.73.1 (system setup)
Commit: 6261075646f055b99068d3688932416f2346dd3b
Date: 2022-11-09T04:27:29.066Z
Electron: 19.0.17
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.19045
Sandboxed: No

The workaround only helps if you are using a Linux distro which still includes OpenSSL 1.1.1, and many of them don’t. I think I have a different workaround, but it’s a bit weird…

First of all, downgrade to 1.25.2 as other posters have suggested. Now go to the directory where the extension is installed, probably ~/.vscode/extensions/ms-dotnettools.csharp-1.25.2-linux-x64. In there you will find two directories, one called .razor and one called .debugger. Both of these directories contain a file called libSystem.Security.Cryptography.Native.OpenSsl.so but they are different.

Copy the file from .debugger to .razor.

To be honest I’m really surprised this works, but it currently seems to be okay on my system. I’ll post again if I wake up and find it’s not working. 😊

I hope we can have a proper fix for this soon—are you (Microsoft) able to reproduce this, and do you need any more information from us?

Thanks for all of the feedback folks, I’ve been able to repro this, and have a PR open to fix it. Unfortunately releasing updates to the extension is a relatively slow process, so you’ll have to bear with us a little longer. Sorry!

image

Latest version of C# extension for VS code. @davidwengier I don’t think this is fixed. Given 14 people now have liked the above comment, I don’t think this should be “Closed”

Same issue here. Downgrading to 1.25.2 fixes my issue.

I just tried the pre-release, and it looks as though the problem is fixed! Thank you for all your hard work on this.

Downgrading to 1.25.2 helps. If you get errors then use CLR_OPENSSL_VERSION_OVERRIDE=1.1 code . to deal with bugs in that version.

This started with version 1.25.4

Hello, I’ve just tried the 1.25.7 release. I’m not sure if that release was intended to have a fix for this issue, but it made no difference for me. The reproduction steps at https://github.com/OmniSharp/omnisharp-vscode/issues/5561#issuecomment-1518364826 still give the same errors.

Thanks @davidwengier, that is a subtle difference indeed. I can PM you an example razor file where on format I get the same error. I will log a new issue

@garrettlondon1 that error appears to come from the semantic tokens system, which is different from formatting, and is coming from the Razor LSP server. Would you might logging it as an issue on https://github.com/dotnet/razor. You should be able to use the Report an Issue feature of the extension, which will include logs and version info etc.

The bug is fixed, but we have not been able to ship a new version of the extension with the fix in it yet. Unfortunately the process is not straight forward.

Adding to the above:

I just installed the latest .Net 7 SDK (7.0.203) and created a new project (dotnet new mvc). Trying to format any of the default .cshtml Razor files causes the same error message.

@davidwengier as you closed this as fixed, is there anything wrong with my setup or is this bug just not actually fixed?

[Edit] Just out of curiosity i installed VS Code Insider and formatting seems to work with C# Ext. 1.25.5. … At least for a few minutes before i ended up getting the same error message as well 😦

@gmkado did 1.25.5 work for you? I installed it a few minutes ago (+ restarted VS Code) and i still get the formatting error message with the log showing this:

Entering method textDocument/formatting.
[Error - 7:21:17 AM] [null]
[Error - 7:21:17 AM] Request textDocument/formatting failed.
  Message: Specified argument was out of the range of valid values. (Parameter 'Range end line 26 matches or exceeds SourceText boundary 26.')
  Code: -32000 
[object Object]

VS Code v1.77.3 C# Ext. 1.25.5 via VSIX .Net 7.0.103

I’ve been on the old version 1.25.2 for all this time, to avoid the bugs in 1.25.4.

But now I updated vscode to 1.76.2 and it broke even more stuff - various code formatting and code completion actions don’t work at all.

So now I need to downgrade both the IDE and extension. 😦

When will the new version be released? I see there already is a beta.

I’m not sure if it’s clear from the comments, but this issue is still a nuisance. It’s possible to get an old version of the C#/Razor extension working using the work-around I described earlier, but it has other bugs which are probably fixed in the later release.

I was wondering if we can expect a new release of the extension soon, given that the problem is evidently fixed in the current sources.

Many thanks for your work on this, and I do understand if it’s difficult to do a release straight away because of other priorities.

This is actually starting to drive me up the wall. Every time I paste in code, or save a file, I get the same error. I’m going to disable formatting for razor files for now. Can also confirm downgrade to v1.25.2 removes the error.

If it helps, I captured some Razor Log below. First, I cleared the log output, then pasted some HTML code to trigger the error. The following log was generated:

[Client - 10:28:07 PM] Updating the HTML document for Razor file 'c:/Projects/FDMWeb/FDMWeb/Views/Personnel/_WCBInjuries.cshtml' (565)
[Client - 10:28:07 PM] Notifying document 'c:\Projects\FDMWeb\FDMWeb\Views\Personnel\_WCBInjuries.cshtml' changed 'htmlChanged'
[Client - 10:28:07 PM] Updating the C# document for Razor file 'c:/Projects/FDMWeb/FDMWeb/Views/Personnel/_WCBInjuries.cshtml' (565)
[Client - 10:28:07 PM] Notifying document 'c:\Projects\FDMWeb\FDMWeb\Views\Personnel\_WCBInjuries.cshtml' changed 'csharpChanged'
[Error - 10:28:07 PM] [null]
[Error - 10:28:07 PM] Request textDocument/rangeFormatting failed.
  Message: Specified argument was out of the range of valid values. (Parameter 'Range start line 131 matches or exceeds SourceText boundary 131.')
  Code: -32000 
[object Object]

Environment Info Version: 1.75.1 (user setup) Commit: 441438abd1ac652551dbe4d408dfcec8a499b8bf Date: 2023-02-08T21:32:34.589Z Electron: 19.1.9 Chromium: 102.0.5005.194 Node.js: 16.14.2 V8: 10.2.154.23-electron.0 OS: Windows_NT x64 10.0.22621 Sandboxed: Yes

C# Extension v1.25.4