Skip to content

Doesn't resolve correct blazor component usings/imports #4580

Closed

Description

Issue Description

Steps to Reproduce

  1. Create a new dotnet blazor server project (dotnet new blazorserver -o test)
  2. Open the project in Visual Studio Code, with the C# extension installed
  3. 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)
info: OmniSharp.Services.DotNetCliService
DotNetPath set to dotnet
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
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"
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: Visual Studio Community 2019 16.9.31205.134 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin"
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
info: OmniSharp.Cake.CakeProjectSystem
Detecting Cake files in 'c:\Users\user\Documents\test\test'.
info: OmniSharp.Cake.CakeProjectSystem
Could not find any Cake files
info: OmniSharp.MSBuild.ProjectSystem
No solution files found in 'c:\Users\user\Documents\test\test'
info: OmniSharp.MSBuild.ProjectManager
Queue project update for 'c:\Users\user\Documents\test\test\test.csproj'
info: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in 'c:\Users\user\Documents\test\test'.
info: OmniSharp.Script.ScriptProjectSystem
Could not find any CSX files
info: OmniSharp.WorkspaceInitializer
Configuration finished.
info: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location 'c:\Users\user\Documents\test\test' on host 7776.
info: OmniSharp.MSBuild.ProjectManager
Loading project: c:\Users\user\Documents\test\test\test.csproj
info: OmniSharp.MSBuild.ProjectManager
Successfully loaded project file 'c:\Users\user\Documents\test\test\test.csproj'.
info: OmniSharp.MSBuild.ProjectManager
Adding project 'c:\Users\user\Documents\test\test\test.csproj'
info: OmniSharp.MSBuild.ProjectManager
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: db7cc87d51

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

Activity

  1. neal2018 commented on Jun 5, 2021

    @neal2018

    Same error. Is there any other workaround besides switching to VS?

  2. angar4ik commented on Jun 7, 2021

    @angar4ik

    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.

  3. deanchalk commented on Jun 8, 2021

    @deanchalk

    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

  4. angar4ik commented on Jun 8, 2021

    @angar4ik

    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

    1.23.9 worked for me! Thank you!

  5. nitrospaz commented on Jun 9, 2021

    @nitrospaz

    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

    Had the same issue, downgraded to 1.23.11 and looks like it is working with the downgrade workaround.

  6. NTaylorMullen commented on Jun 9, 2021

    @NTaylorMullen

    Could you all verify if this is what you're running into: #4573

    Specifically the mentioned NRE in the OmniSharp log:
    image

  7. Xeevis commented on Jun 11, 2021

    @Xeevis

    Oddly enough downgrading to 1.23.11 fixed the issue, but then I upgraded back to 1.23.12 and it keeps working. 😵

  8. jtsom commented on Jun 25, 2021

    @jtsom

    Having similar issue. New BlazorWasm application has many errors/warnings. Downgrading to 1.23.11 fixes the issue. (reinstalling 1.23.12 just brought the errors back)

  9. ronascentes commented on Jun 30, 2021

    @ronascentes

    1.23.11 works for me also. Hope it get fixed by 1.23.13 release.

  10. ronascentes commented on Jun 30, 2021

    @ronascentes

    It seems the tracking work is here: #33858

  11. lucianotres commented on Aug 8, 2023

    @lucianotres

    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.

  12. andrejpanjan commented on Aug 10, 2023

    @andrejpanjan

    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.

    Same for me.

  13. blackshot commented on Sep 9, 2023

    @blackshot

    same issue here. if downgrade is required, C# dev kit extension becomes unusable.

  14. 23 remaining items

  15. rfrancisco commented on Jan 26, 2024

    @rfrancisco

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

    1. Clone a fresh repo
    2. Restore MAUI workloads
    3. Rebuild the solution, first time it takes a while
    4. Open a file - EventComponent.razor will do.

    Symptoms seem consistent with what's described here. Specifically:

    1. _Imports.razor usings aren't resolved
    2. Inline components (no code behind class) don't seem to be registered as namespaces by the compiler.
    3. Custom components are not resolved (RZ10012) - this is true even if I add the relevant using in the same file.

    If you need something else to debug this, please share.

    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.

  16. AdamJonsson commented on Jan 26, 2024

    @AdamJonsson

    Have the same issue when I reference any of my components. However, when I open the referenced component in VSCode, the "Razor(RZ10012)" warning disappears.

    I do not have the issue when I am creating a new dotnet new project on the same computer. I tried "dotnet clean" on the existing project but it changed nothing. Using .NET 8 as target platform for the existing and new projects.

    I also tried creating a new project with over 500 small components and get the same behaviour for a few seconds, but then it seems to resolve itself somehow. I struggling to find why this is not happening on the existing project. My only guess currently is that it is the size of the project...

    When using OmniSharp the "Razor(RZ10012)" is NOT appearing, it is only when I am using C# Dev Kit

  17. marcos-prins commented on Jun 16, 2024

    @marcos-prins

    Getting the same error Razor(RZ10012) for common blazor components. Intellisense is basically broken. Downgrading C# extension solve the error, but then, I cannot build or debug to my android device

    Screenshot from 2024-06-16 17-13-27

  18. WolfBublitz commented on Jun 23, 2024

    @WolfBublitz

    I can confirm that this is not working. I am using latest C# Dev Kit (1.8.8) and in a freshly created project via
    dotnet new blazorwasm
    the namespace of the project and the App component is marked as unknown as shown in this screenshot:
    Bildschirmfoto 2024-06-23 um 20 29 29

  19. WolfBublitz commented on Jun 25, 2024

    @WolfBublitz

    I have tracked down the C# extension versions:

    • 2.30.28 works
    • 2.31.16 does not work
  20. marcos-prins commented on Jun 25, 2024

    @marcos-prins

    I have tracked down the C# extension versions:

    • 2.30.28 works
    • 2.31.16 does not work

    Solves partially. Sometimes doesn't recognize components until the .razor file of the component is opened

  21. BartNetJS commented on Jun 26, 2024

    @BartNetJS

    Working for me on version v2.34.12
    Tested with pre-release and got the issue back

  22. jtsom commented on Jun 26, 2024

    @jtsom

    There's a big issue with the latest versions (after 2.32.14) where the dev console is filled up with errors, that also manifest with incorrect Razor errors showing. It was transferred to the Razor repo. Hopefully will get fixed.

    #7246

  23. jtsom commented on Jun 26, 2024

    @jtsom

    I noticed in the changelog for 2.33.17 (where the problem first occurs) that Razor was updated to prerelease of v9:
    Bump Razor to 9.0.0-preview.24281.3

  24. M0n7y5 commented on Jul 17, 2024

    @M0n7y5

    Jesus Christ it is 2+ years. Every time i try to open my existing Blazor project in VSCode with the latest or preview version of the C# extension i get 50 to 100 problems. The numbers of problems jumps around that number over time for no reason and even when i am not touching anything. LSP constantly throws bunch of errors almost every time i try hover over on some class type.

    The fact that it doesn't even work with the official templates from dotnet CLI after 2+ years tells me that MS does not want this to work in order to get more users on Visual Studio Community/Pro.

  25. davidwengier commented on Jul 18, 2024

    @davidwengier
    Member

    Jesus Christ it is 2+ years.

    Nah, the C# extension, which is this repo, is not nearly that old. There was OmniSharp before it and that might have had some of the same bugs, but the amount of changes both in Roslyn and Razor since then is huge, and it's not fair to blame OmniSharp for our bugs. We earned ours fair and square, all on our own!

    MS does not want this to work in order to get more users on Visual Studio Community/Pro.

    Unfortunately nobody told any of us on the team this, and we've accidentally published v2.39.28 (pre-release) which hopefully fixes the issue, or at the very least makes it a lot less prevalent. If only you got here sooner to warn us.

    If anyone wants to update and try it out, please do let us know how it goes. Of course we probably will be unable to respond because we'll have all been fired due to the resultant slowing sales of VS Community. Then again VS Community is free so maybe we'll get away with it?

  26. jtsom commented on Jul 18, 2024

    @jtsom

    There's a big issue with the latest versions (after 2.32.14) where the dev console is filled up with errors, that also manifest with incorrect Razor errors showing. It was transferred to the Razor repo. Hopefully will get fixed.

    #7246

    Is it too much to hope that this nasty problem is fixed with this update? I didn't see any reference in the update notes. Will check, with fingers crossed.

  27. davidwengier commented on Jul 18, 2024

    @davidwengier
    Member

    For context, the big update here is a complete change in how we sync data between Roslyn and Razor, from being file based to using a named pipe. This avoids a bunch of potential races and issues, for example I/O contention on the Roslyn side as its writing the file, if events come in at the same time, or missed file system events on the Razor side where it detects that the file has been updated.

    Unfortunately @jtsom the issue that you are referencing is unlikely to be directly solved by this change. There is a chance that a more reliable system underneath makes everything on top work better - perhaps there are assumptions in the code being violated by bad communication - but I wouldn't want to give you any false hope. Your issue is currently tracked by dotnet/razor#10505 which is still open, and is being investigated.

  28. xtellurian commented on Jul 19, 2024

    @xtellurian

    @davidwengier upgrading to v2.39.28 (pre-release) fixed a lot of the issues I was having in VS code.

    Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions