-
Notifications
You must be signed in to change notification settings - Fork 675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doesn't resolve correct blazor component usings/imports #4580
Comments
Same error. Is there any other workaround besides switching to VS? |
same here. Code template generated by dotnet new command Compiling without a problem. |
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! |
Had the same issue, downgraded to 1.23.11 and looks like it is working with the downgrade workaround. |
Could you all verify if this is what you're running into: #4573 |
@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) |
Oddly enough downgrading to 1.23.11 fixed the issue, but then I upgraded back to 1.23.12 and it keeps working. 😵 |
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) |
1.23.11 works for me also. Hope it get fixed by 1.23.13 release. |
It seems the tracking work is here: #33858 |
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. |
same issue here. if downgrade is required, C# dev kit extension becomes unusable. |
Can reproduce as of the latest prerelease. Also getting |
tagging @davidwengier for a Razor issue |
dotnet/razor#9265 fixes this. Will see if I can repro the other issues, but would appreciate any Razor Log output from anyone reproing this issue in the latest C# extension version. |
@davidwengier Thanks for looking into this. Here is the Razor Log from my project, where IntelliSense works fine in Visual Studio, but not in VS Code (Preview). razor-logs-from-my-project.txt - standard logs Most of the log entries mention that there's |
Solution structure (stripped out all unnecessary context)
_Imports.cs @using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
@using Microsoft.JSInterop
@using WebIndemnizacionesVM
@using WebIndemnizacionesVM.Shared
@using WebIndemnizacionesVM.Shared.Componentes
@using WebIndemnizacionesVM.Data
@using WebIndemnizacionesVM.Data.Microservicios
@using Compartido.DTO.Microservicios.Login
@using System.ComponentModel.DataAnnotations
@using Blazored.Toast
@using Blazored.Toast.Services
@using Blazored.Modal
@using Blazored.Modal.Services
@using MudBlazor
@using CurrieTechnologies.Razor.SweetAlert2
@using Compartido.Utils MainLayout.razor Razor-logs.log also... Why component syntax color are red in pre-release version? UPDATE: added verbose logs |
@blackshot To set verbosity, open File -> Preferences -> Settings and search for |
Thanks, i updated the comment with the verbose logs |
Thanks for the logs @blackshot The good news is that the red component tags are fixed by #6304, so should be in a release soon. Is there anything "interesting" about NavMenu? An @PeterDraex thank you also for the logs. Other than a couple of requests at the start where folding range requests failed (thats trying to get the areas that can be collapsed with the little arrows in the editor margin) everything looks fine, but perhaps there are requests that are supposed to be there that never happened. When you say "IntelliSense", what exactly do you mean? Do you mean the light bulb suggestions, or the completion suggestions as you type? The logs you attached don't seem to have any typing in them, but I can see a few light bulb requests. Unfortunately nothing that indicates a problem, though to be fair we also don't log if we're returning 0 or 100 lightbulb actions. If the issue is with lightbulbs no showing, which one(s) were you expecting? Unfortunately for various technical reasons VS and VS Code are not quite at parity with which Razor lightbulbs they support, specifically the "Add using" can't be offered in VS Code. The "no project context" thing can be ignored, VS Code doesn't support that (yet!), and it doesn't indicate a problem. Just means there wasn't a project context sent with the request, so we'd operate on the default context. Totally expected in VS Code. |
@davidwengier My file
VS Code is reporting a problem:
When I locate my cursor after Here's a new log file, while the error was displayed, I tried bringing up the suggestions and going to definition. Is it helpful? |
Thanks for that info, thats very helpful. Unfortunately I'm not sure how helpful I can be. I can think of two possibilities:
Unfortunately without access to the code it will be hard to diagnose this one with just the logs. Don't suppose its open source? :) One other option is to use the "Razor: Show Razor CSharp" function in VS Code when you have To be very clear here, I'm not saying this isn't a Razor bug, or that it's your codes fault, just that it seems to be something to do with the compiled files, and the compiler doesn't have any logs we can access. The project state seems to be correct from the logs, though if the namespace in the generated files are wrong, then clearly that's not the case. |
(adding some components to the context in order to understand NavMenu.razor)
I think there is nothing special in NavBar.razor, but razor couldn't find "WebIndemnizacionesVM.Shared.Componentes.SideBarComps" namespace when i opened the NavBar.razor file. Couldn't find "Protegido" neither which is imported in _Imports.razor NavBar.razor @using Compartido.DTO.Microservicios.PermisosWebIndemnizacionVM;
@using WebIndemnizacionesVM.Shared.Componentes.SideBarComps
@inject NavigationManager NM;
@inject SessionService ss;
@code{
[CascadingParameter]
RespuestaLogin? login { get; set; }
[CascadingParameter]
Permisos? permisos { get; set; }
}
<nav class="navbar fixed-top navbar-expand-lg bg-white shadow-sm px-3" style="z-index: 10;">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="@NM.ToAbsoluteUri("img/hdi_seguros_logo2018_rgb-80px.png")" class="logo" alt="">
</a>
<button class="navbar-toggler button-small hdi-btn-tertiary" type="button" data-bs-toggle="collapse" data-bs-target="#menuMobile" aria-controls="menuMobile" aria-expanded="false" aria-label="Toggle navigation">
<i class="fa fa-bars"></i>
</button>
<div class="collapse navbar-collapse" id="menuMobile">
<ul class="nav navbar-nav mt-4 d-lg-none">
@if (permisos is null)
{
<SpinnerHDI />
}
else
{
<Protegido Permiso="BAND-GEST">
<NavItem Icono="fa fa-check" Texto="Casos gestionados" Url="" />
</Protegido>
<Protegido Permiso="SEC-PT">
<NavItemDropdown Icono="fa-solid fa-car-burst" Texto="Pérdidas Totales">
<Protegido Permiso="BAND-PEND">
<NavItem Icono="fa fa-edit" Texto="Casos pendientes" Url="perdidas-totales/" Match="NavLinkMatch.All" />
</Protegido>
</NavItemDropdown>
</Protegido>
<Protegido Permiso="SEC-PP">
<NavItemDropdown Icono="fas fa-building" Texto="Pérdidas Parciales">
<Protegido Permiso="BAND-PEND-PP">
<NavItem Icono="fa fa-check" Url="perdidas-parciales/" Texto="Casos pendientes" Match="NavLinkMatch.All" />
</Protegido>
</NavItemDropdown>
</Protegido>
<Protegido Permiso="BAND-AUTH">
<NavItem Icono="fa fa-lock" Texto="Pendientes autorización" Url="bandeja-autorizacion" />
</Protegido>
<Protegido Permiso="BAND-BLOQ">
<NavItem Icono="fa fa-ban" Texto="Casos bloqueados" Url="bandeja-bloqueados" />
</Protegido>
}
@*<NavItemDropdown Icono="fa-solid fa-car-burst" Texto="Submenu links" >
<NavItem Url="subitems/uno" Texto="Sub item 1" />
<NavItem Url="subitems/dos" Texto="Sub item 2" />
</NavItemDropdown>
<NavItem Icono="fa-solid fa-house-crack" Texto="Recepción de vehículos" Url="recepcion-vehiculo" />
<NavItem Icono="fa-solid fa-circle-dollar-to-slot" Texto="Pagos disponibles" Url="pagos-disponibles" />*@
@*<NavItem Icono="fa fa-user" Texto="Mi perfil" Url="mi-perfil" />*@
<NavItem Icono="fa fa-lock" Texto="Cerrar sesión" Url="#" @onclick=@ss.CerrarSesion/>
</ul>
</div>
<form class="d-flex align-items-center hidden-xs hidden-sm" role="search">
@*<div class="hdi-form-small m-0 mr-3">
<input type="text" class="hdi-form-small-input m-0" placeholder="Buscar">
<i class="fa fa-search hdi-form-small-input-icon"></i>
</div>*@
@if (login is not null)
{
<div class="dropdown">
<button class="button-small hdi-btn-primary" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="fa-regular fa-user"></i> Bienvenido @login?.Usuario.Nombre <i class="fa fa-chevron-down"></i>
</button>
<ul class="dropdown-menu dropdown-menu-end">
@*<li><a class="dropdown-item" href="@NM.ToAbsoluteUri("mi-perfil")"><i class="fa-regular fa-user mr-1"></i> Mi Perfil</a></li>*@
<li><a class="dropdown-item" href="#" @onclick=@ss.CerrarSesion><i class="fa fa-lock mr-1"></i> Cerrar sesión</a></li>
</ul>
</div>
}
</form>
</div>
</nav> check this out, while i was writting this, i just restarted vscode with NavBar.razor file opened in order to generate a clean log with the error. and this happened... It loaded well WebIndemnizacionesVM.Shared.Componentes.SideBarComps namespace and its containing components that couldn't load the first time. UPDATE: i restarted it again doing nothing more than pressing the close button of vscode and reopened it aaaaand... first imported just fine SideBarComps (thats why NavItem is green) then without doing nothing (just stared at it) lost its references. here is the log |
Indeed, its odd that you would get a green tag with a "could not find component" warning, as both come from data the compiler provides us. What might have happened is that after the project first loaded, and everything was fine, something updated the project.razor.vscode.json file and left out those components for some reason, but VS Code doesn't refresh colors very often. FYI @phil-allen-msft since I'm OOF for a few weeks. Looks like something odd happening with component discovery, potentially inconsistent project loading and Roslyn giving us mixed info for the project.razor.vscode.json file, or possibly an issue with different events fighting over writing that file. Seems like its inconsistent and will probably be hard to repro unfortunately. A slightly more complication project that normal might help |
it was a typo writting here in github, foldername is fine |
just in case is helpful, here are my enabled extensions at the moment bug happened.
|
After update to a new version of VS Code Insiders, I am seeing an Expand logs
|
@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:
Symptoms seem consistent with what's described here. Specifically:
If you need something else to debug this, please share. |
@achobanov I'm still experiencing the issue as well |
@achobanov do you have a When I cloned your repo locally, I couldn't get anything restoring or building, but I suspect that is due to missing .NET SDKs. Your global.json targets Unfortunately we don't have a good story for logging anything when the If project information isn't available to Razor this will be "ASP" or even "__GeneratedComponent" |
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. |
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 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 |
I have tracked down the C# extension versions:
|
Solves partially. Sometimes doesn't recognize components until the .razor file of the component is opened |
Working for me on version v2.34.12 |
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. |
I noticed in the changelog for 2.33.17 (where the problem first occurs) that Razor was updated to prerelease of v9: |
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. |
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!
Unfortunately nobody told any of us on the team this, and we've accidentally published 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? |
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. |
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. |
@davidwengier upgrading to Thank you! |
Issue Description
Steps to Reproduce
dotnet new blazorserver -o test
)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
fileUpdate
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
C# log
C# 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
The text was updated successfully, but these errors were encountered: