vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

Formatting Razor File errors with "Request textDocument/formatting failed"

Open seangwright opened this issue 3 years ago • 46 comments

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

seangwright avatar Jan 26 '23 23:01 seangwright

This started with version 1.25.4

lonix1 avatar Jan 27 '23 00:01 lonix1

I also get dozens of errors like this: Request textDocument/linkedEditingRange failed. Unsure if it's related.

lonix1 avatar Jan 27 '23 15:01 lonix1

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

kirse avatar Jan 28 '23 02:01 kirse

Same issue here. Downgrading to 1.25.2 fixes my issue.

h4n0 avatar Jan 28 '23 17:01 h4n0

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.

lonix1 avatar Jan 29 '23 08:01 lonix1

I have the same issue with the latest version 1.25.4 Downgrading and applying the above described fixes works but would be nice to have a fix for that in the next version.

brokelyn avatar Feb 02 '23 15:02 brokelyn

@allisonchou @davidwengier FYI

dibarbet avatar Feb 07 '23 02:02 dibarbet

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?

PeteX avatar Feb 22 '23 13:02 PeteX

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

keefer1707 avatar Feb 23 '23 06:02 keefer1707

This was fixed by https://github.com/dotnet/razor/pull/8318

davidwengier avatar Feb 26 '23 21:02 davidwengier

Same issue here. Downgrading to 1.25.2 fixes my issue.

Same issuse, This works, Downgrading to 1.25.2 fixes my issue.

ImRLopezAG avatar Feb 27 '23 15:02 ImRLopezAG

I have this issue but suddenly after updating my visual Code, errors and warning removed and my razor pages work like last good days. The other thing I changed which may be important is that, I realized that already Visual Studio knows by default that which formatter (OmniSharp C# or Prettier) it should apply according to file format. So I reset all my user and workspace (an folder) setting regarded to format to default (except format on Save tick). This altough seems unrelated but that may work for you. I am using VS Code Version 1.76.0 and C# for Visual Studio Code (powered by OmniSharp). V 1.25.4

abdollahkahne avatar Mar 07 '23 11:03 abdollahkahne

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.

PeteX avatar Mar 14 '23 11:03 PeteX

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.

lonix1 avatar Mar 18 '23 00:03 lonix1

If anyone is coming here looking for a fix, 1.25.5 is not in the extensions marketplace yet but you can install it by following the instructions here: https://github.com/OmniSharp/omnisharp-vscode/wiki/Installing-Beta-Releases

gmkado avatar Apr 19 '23 18:04 gmkado

@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

tkoenig89 avatar Apr 20 '23 05:04 tkoenig89

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 :(

tkoenig89 avatar Apr 20 '23 05:04 tkoenig89

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.

davidwengier avatar Apr 20 '23 06:04 davidwengier

@tkoenig89 it has been working for me so far. My versions: VS Code v1.77.2 C# Ext. 1.25.5 via VSIX .Net 6.0.401

gmkado avatar Apr 20 '23 07:04 gmkado

@tkoenig89 it has been working for me so far. My versions: VS Code v1.77.2 C# Ext. 1.25.5 via VSIX .Net 6.0.401

Thanks. It might be an issue with .Net 7. As the initial issue appeared months ago when we upgraded .Net 6 to .Net 7.

tkoenig89 avatar Apr 20 '23 07:04 tkoenig89