razor icon indicating copy to clipboard operation
razor copied to clipboard

Razor ist not working with any constellation of extensions

Open Kokujou opened this issue 2 years ago • 6 comments

I'm sorry this report is going to be messy because i don't even know where to start...

i played around with preview versions and omnisharp on/off and stuff and here are some things i noticed:

  1. global razor-usings are not being considered - (_imports.razor @using directive)
  2. html tags are shown as red but you can navigate
  3. c# properties are shown as strings but can also be navigated with
  4. razor injects are not detected in c# code resulting in a pseudo-error (compiling works)
  5. formatting is broken (Request textDocument/formatting failed. Message: Specified argument was out of the range of valid values. (Parameter 'Range end line 43 matches or exceeds SourceText boundary 43.')

i'm using blazor with .razor pages and codebehind, i also have both razor and c# global imports.

so if anyone got this to work like expected, please tell me what configuration you used so i can get it too

Kokujou avatar Sep 15 '23 10:09 Kokujou

Thanks for the report @Kokujou. Could you let us know what version of the C# extension you're using, and whehter you have the C# Dev Kit installed too?

The red component tags was fixed in https://github.com/dotnet/vscode-csharp/pull/6304 but I'm not sure if that has been released in a version yet.

If you can include the contents of the Razor Log output it might help us track down what is going on, and should also tell us which Razor server version you have.

davidwengier avatar Sep 15 '23 11:09 davidwengier

i used multiple and i also tried the c# dev kit, both in the current release version and the pre-release version so this would be: C# 2.1.2 + 2.1.10 C# Dev Kit 0.4.10 + 0.5.47

the only part in the razor logs that seemed relevant to me is the formatting error that i already quoted: Parameter 'Range end line 43 matches or exceeds SourceText boundary 43.')

Kokujou avatar Sep 15 '23 11:09 Kokujou

@Kokujou does this happen in every Blazor project you work with, or just a particular one? Are there any repro steps you can share to help diagnose issues, and/or a sample project you can provide us?

allisonchou avatar Oct 03 '23 03:10 allisonchou

yeah the issue is in every razor project i work on. I think it's quite hard to overlook but of course you need a global _Imports.razor file. i mean we do use mudblazor in our project but this is probably quite unrelated. i also tried using completely empty files to format and got the same formatting error

take this here for example grafik you see this is actually a property. but first of all ScrollBottom is not marked as a property and second of all, the content is also not marked as c#-code.

i mean if you know how to not reproduce it i would be eager to know ^^ i wonder if it's maybe some c# - razor mixture is not properly detected and therefore breaks all following code or so

btw i do have a second project that i could hypothetically share, but it's only half-done and uses blazor in WPF scope, so i don't even know if this is inside your specifications, and in this project formatting doesn't even get applied, no error, no nothing. and OmniSharp complains about some Windows Forms stuff not being found. (works in Visual Studio of course). i mean it's a language formatter and shouldn't have that much to do with what the wrapper is, but you never know.

Kokujou avatar Oct 03 '23 08:10 Kokujou

Thanks for the information @Kokujou! I believe colorization issues you're seeing are another instance of https://github.com/dotnet/razor/issues/9336. I'll see if we can get that work scheduled on our roadmap.

in this project formatting doesn't even get applied, no error, no nothing

Regarding broken formatting, do you have this option checked? image

We were previously seeing issues with formatting not applying properly when this option was disabled.

Sharing the project would be helpful for diagnosing issues. Even if it's not in our scope, we can route the bugs to whichever team owns the specific area.

allisonchou avatar Oct 03 '23 23:10 allisonchou

in this case feel free to have a look on this project, i'm currently playing around with migrating a javascript application to blazor hybrid

https://github.com/Kokujou/ObscuritasMediaManager/tree/master/ObscuritasMediaManager.Client

in the default configuration of vscode, i already see the first issues in the file pages/MusicPlaylistPage.razor first of all formatting is completely not working, the coloring is mostly not applied (but you already mentioned there is already a ticket so thanks for that :) )

I don't know if i'm missing something that the formatting is not getting applied even when i use F1 -> Format Document (Forced), in the other project that i cannot share at least that works, but i'm getting the error documented above, but as i said that might be related to my current experimental state.

i also see errors like: "Trying to create DocumentContext for razor/mapToDocumentRanges, with no project context," maybe this is saying you something?

Kokujou avatar Oct 04 '23 06:10 Kokujou

Not Validated. Issue still persist.

ms-dotnettools.csharp.zip

syrle-foronda avatar Oct 13 '25 22:10 syrle-foronda

@syrle-foronda this issue is a little vague and reports a few different things. Could you be specific about which issue you saw still persisting?

davidwengier avatar Oct 17 '25 01:10 davidwengier

@davidwengier
this image creates the issue no 5 Image

2025-10-17 10:54:29.427 [error] Document pull failed for text document file:///c%3A/Users/v-syforonda/Documents/BlazorApp1/Components/Pages/ForceIssues.razor TypeError: range must be set at new Nf (file:///c:/Users/v-syforonda/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:110:14219) at new t7 (c:\Users\v-syforonda\.vscode\extensions\ms-dotnettools.csharp-2.94.41-win32-x64\dist\extension.js:51:63763) at l (c:\Users\v-syforonda\.vscode\extensions\ms-dotnettools.csharp-2.94.41-win32-x64\dist\extension.js:51:85049) at s (c:\Users\v-syforonda\.vscode\extensions\ms-dotnettools.csharp-2.94.41-win32-x64\dist\extension.js:51:57304) at Object.Hnt (c:\Users\v-syforonda\.vscode\extensions\ms-dotnettools.csharp-2.94.41-win32-x64\dist\extension.js:51:57390) at Object.c [as asDiagnostics] (c:\Users\v-syforonda\.vscode\extensions\ms-dotnettools.csharp-2.94.41-win32-x64\dist\extension.js:51:84919) at isDisposed.client.isRunning.client.sendRequest.then.client.handleFailedRequest.kind (c:\Users\v-syforonda\.vscode\extensions\ms-dotnettools.csharp-2.94.41-win32-x64\dist\extension.js:54:10794) at Object.xB [as provideDiagnostics] (c:\Users\v-syforonda\.vscode\extensions\ms-dotnettools.csharp-2.94.41-win32-x64\dist\extension.js:1213:5082) at I7.pullAsync (c:\Users\v-syforonda\.vscode\extensions\ms-dotnettools.csharp-2.94.41-win32-x64\dist\extension.js:54:7401) 2025-10-17 10:54:51.925 [error] Request textDocument/codeAction failed. Message: (6,71) matches or exceeds SourceText boundary 211. Code: -32000 [object Object] 2025-10-17 10:58:55.071 [error] Request textDocument/codeAction failed. Message: (6,71) matches or exceeds SourceText boundary 211. Code: -32000 [object Object] 2025-10-17 11:08:35.578 [error] Request textDocument/codeAction failed. Message: (6,71) matches or exceeds SourceText boundary 211. Code: -32000 [object Object] 2025-10-17 11:08:48.489 [error] Request textDocument/codeAction failed. Message: (6,71) matches or exceeds SourceText boundary 211. Code: -32000 [object Object] 2025-10-17 11:08:49.608 [error] Request textDocument/codeAction failed. Message: (6,71) matches or exceeds SourceText boundary 211. Code: -32000 [object Object]

syrle-foronda avatar Oct 17 '25 18:10 syrle-foronda

ms-dotnettools.csdevkit.zip

for reference

syrle-foronda avatar Oct 17 '25 18:10 syrle-foronda

@syrle-foronda We recently added some more logging for formatting that should help us track this down. Could I trouble you to grab some extra logs of the formatting operation, and upload them? Instructions are here: https://github.com/dotnet/razor/blob/main/docs/Formatting.md#turn-on-formatting-logging

NOTE: This is only available in v2.96.x and above, so current pre-release should work fine.

davidwengier avatar Oct 24 '25 22:10 davidwengier

@davidwengier just done with revalidating the above issues it was a false positive on my end as it is already fixed. this issue is now Validated

syrle-foronda avatar Oct 28 '25 18:10 syrle-foronda