vscode-csharp: Doesn't resolve correct blazor component usings/imports
Issue Description
Steps to Reproduce
- Create a new dotnet blazor server project (
dotnet new blazorserver -o test
) - Open the project in Visual Studio Code, with the C# extension installed
- Open any file which uses components (such as
Shared/MainLayout.razor
) and the_Imports.razor
file
(Note that this does not happen in Visual Studio 2019)
Expected Behavior
This extension doesn’t show any errors for the generated code
Actual Behavior
All components used in Blazor html markup and in C# @code
sections (not present in the generated code) are highlighted in blue or red (info/error) because the extension fails to identify and resolve correct @using
directives in the top-level _Imports.razor
file
Update
I have disabled all extensions except for the OmniSharp C# one and it is still reporting every single component usage as an error.
Logs
OmniSharp log
OmniSharp log
Starting OmniSharp server at 29.5.2021, 21:14:17
Target: c:\Users\user\Documents\test\test
OmniSharp server started.
Path: c:\Users\user.vscode\extensions\ms-dotnettools.csharp-1.23.12.omnisharp\1.37.10\OmniSharp.exe
PID: 11868
Starting OmniSharp on Windows 6.2.9200.0 (x64)
DotNetPath set to dotnet
Located 2 MSBuild instance(s)
1: Visual Studio Community 2019 16.9.31205.134 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin"
2: StandAlone 16.11.0 - "c:\Users\user\.vscode\extensions\ms-dotnettools.csharp-1.23.12\.omnisharp\1.37.10\.msbuild\Current\Bin"
Registered MSBuild instance: Visual Studio Community 2019 16.9.31205.134 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin"
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
Detecting Cake files in 'c:\Users\user\Documents\test\test'.
Could not find any Cake files
No solution files found in 'c:\Users\user\Documents\test\test'
Queue project update for 'c:\Users\user\Documents\test\test\test.csproj'
Detecting CSX files in 'c:\Users\user\Documents\test\test'.
Could not find any CSX files
Configuration finished.
Omnisharp server running using Stdio at location 'c:\Users\user\Documents\test\test' on host 7776.
Loading project: c:\Users\user\Documents\test\test\test.csproj
Successfully loaded project file 'c:\Users\user\Documents\test\test\test.csproj'.
Adding project 'c:\Users\user\Documents\test\test\test.csproj'
Update project: test
C# log
C# log
*empty log*
Environment information
VSCode version: 1.56.2 C# Extension: 1.23.12
Dotnet Information
.NET SDK: Version: 5.0.202 Commit: db7cc87d51Runtime: OS Name: Windows OS Version: 10.0.19042 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.202\
Host (useful for support): Version: 5.0.5 Commit: 2f740adc14
.NET SDKs installed: 3.1.408 [C:\Program Files\dotnet\sdk] 5.0.202 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.All 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions
Extension | Author | Version |
---|---|---|
aspnetcorerazor-html-css-class-completion | kevin-chatham | 1.0.3 |
auto-close-tag | formulahendry | 0.5.10 |
auto-complete-tag | formulahendry | 0.1.0 |
auto-rename-tag | formulahendry | 0.1.6 |
auto-using | Fudge | 0.7.15 |
autoimport | steoates | 1.5.4 |
blazorwasm-companion | ms-dotnettools | 1.1.0 |
bracket-pair-colorizer-2 | CoenraadS | 0.2.0 |
browserslist | webben | 1.1.0 |
code-spell-checker | streetsidesoftware | 1.10.2 |
codespaces | GitHub | 0.10.4 |
comment-ts | salbert | 1.0.21 |
csharp | ms-dotnettools | 1.23.12 |
csharp-colors | logerfo | 0.1.8 |
cshtml | fireside21 | 0.1.3 |
debugger-for-chrome | msjsdiag | 4.12.12 |
docfx-assistant | tintoy | 0.1.5 |
docomment | k–kato | 0.1.20 |
dotenv | mikestead | 1.0.1 |
easyzoom | NabeelValley | 0.1.0 |
EditorConfig | EditorConfig | 0.16.4 |
fluent-icons | miguelsolorio | 0.0.11 |
format-selection-as-html | adrianwilczynski | 2.3.0 |
git-graph | mhutchie | 1.30.0 |
github-markdown-preview | bierner | 0.0.2 |
github-vscode-theme | GitHub | 4.1.1 |
gitignore | codezombiech | 0.7.0 |
gitlens | eamodio | 11.4.1 |
headwind | heybourn | 1.7.0 |
html-css-class-completion | Zignd | 1.20.0 |
html-slim-scss-css-class-completion | gencer | 1.7.8 |
JSDocTagComplete | HookyQR | 0.0.2 |
markdown-checkbox | bierner | 0.1.3 |
markdown-emoji | bierner | 0.1.0 |
markdown-preview-github-styles | bierner | 0.2.0 |
markdown-yaml-preamble | bierner | 0.0.4 |
material-icon-theme | PKief | 4.7.0 |
material-product-icons | PKief | 1.0.4 |
material-theme | zhuangtongfa | 3.10.14 |
npm-intellisense | christian-kohler | 1.3.1 |
postcss | csstools | 1.0.9 |
prettier-vscode | esbenp | 6.4.0 |
quokka-vscode | WallabyJs | 1.0.369 |
razor-plus | austincummings | 0.1.4 |
remote-containers | ms-vscode-remote | 0.177.2 |
remote-wsl | ms-vscode-remote | 0.56.3 |
svelte-autoimport | pivaszbs | 1.0.4 |
svelte-extractor | proverbialninja | 0.0.3 |
svelte-intellisense | ardenivanov | 0.7.1 |
svelte-vscode | svelte | 105.0.0 |
tailwind-docs | austenc | 1.4.0 |
tailwind-sass-syntax | macieklad | 1.3.0 |
theme-dracula | dracula-theme | 2.22.3 |
vscode-docker | ms-azuretools | 1.13.0 |
vscode-dotnet-runtime | ms-dotnettools | 1.1.0 |
vscode-eslint | dbaeumer | 2.1.20 |
vscode-firefox-debug | firefox-devtools | 2.9.4 |
vscode-html-css | ecmel | 1.10.2 |
vscode-html-scss | P-de-Jong | 0.0.42 |
vscode-language-babel | mgmcdermott | 0.0.31 |
vscode-npm-script | eg2 | 0.3.21 |
vscode-pull-request-github | GitHub | 0.26.0 |
vscode-sqlite | alexcvzz | 0.12.0 |
vscode-stylelint | stylelint | 0.86.0 |
vscode-tailwindcss | bradlc | 0.6.6 |
vscode-versionlens | pflannery | 1.0.9 |
vscode-yaml | redhat | 0.19.2 |
vscodeintellicode | VisualStudioExptTeam | 1.2.14 |
zoombar-vscode | wraith13 | 1.4.0 |
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 22
- Comments: 34 (7 by maintainers)
Hi All, had the same issue. I found a work-around in VS Code by downgrading the C# extension from the current version 1.23.12 to 1.23.11. You can do this in the the extensions panel by clicking on the config button for the C# extension and click ‘Install another version’, then select the previous version. Version 1.23.12 was released about 12 days ago, and obviously has broken razor intellisense
This issue seems to be back with the new v2 C# extension. The _Imports.razor file it’s complete ignored, then the intellisense go nutz.
The downgrade it’s a working around, going back to v1.26.0 solved it for me.
I’m also experiencing the same issue but I found a workaround and hope it helps troubleshoot the issue. Just like others have said I’m also having issues with some components not being picked up by vscode (RZ10012) and I noticed that some work ok, while others don’t. After some experimentation, I noticed that the components that were being picked-up correctly were using a .cs partial class and they explicitly inherited from ComponentBase in the c# partial class cs file. I started refactoring all components to have a cs file with a partial class, even those without any code block, and one by one they started working as soon as I added the ComponentBase inheritance in the c# partial class. This is far from a solution because while CS code behind files is great for complex components its not ideal for very simple components or components that don’t even require a “@code” block. Hope this helps you get to the bug and find a solution.
Also, before finding this workaround I noticed that components that were not being picked-up started to do so after opening the component file in vscode.
@blackshot, @PeterDraex no resolution on this?
@davidwengier I’m facing the same issue right now and my project is open. I’ve created a snapshot branch here.
It’s working like a charm in VS, hit this issue as I’m trying out VS Code as alternative:
EventComponent.razor
will do.Symptoms seem consistent with what’s described here. Specifically:
If you need something else to debug this, please share.
@blackshot To set verbosity, open File -> Preferences -> Settings and search for
razor.trace
Same for me.
same here. _Imports.razor: error finding .Shared folder; App.razor: Router component can’t be found;
Code template generated by dotnet new command
Compiling without a problem.
After update to a new version of VS Code Insiders, I am seeing an
System.InvalidOperationException
in C# Output window, coming from LanguageServerHost.Expand logs
it was a typo writting here in github, foldername is fine
Thanks, i updated the comment with the verbose logs
Can reproduce as of the latest prerelease. Also getting
'RenderTreeBuilder' does not contain a definition for 'AddComponentParameter' and no accessible extension method 'AddComponentParameter' accepting a first argument of type 'RenderTreeBuilder' could be found (are you missing a using directive or an assembly reference?)
repeatedly from intellisense.Oddly enough downgrading to 1.23.11 fixed the issue, but then I upgraded back to 1.23.12 and it keeps working. 😵
@NTaylorMullen I attached my OmniSharp log in my issue. It doesn’t throw an unhandled exception of any kind, and I’m targeting .NET 5, not 6, so I don’t think #4573 relates to this one (this appears to describe the same issue though: dotnet/aspnetcore#33350)