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

Doesn't resolve correct blazor component usings/imports

Open ghost opened this issue 3 years ago β€’ 41 comments

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

ghost avatar May 29 '21 19:05 ghost

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

neal2018 avatar Jun 05 '21 11:06 neal2018

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.

angar4ik avatar Jun 07 '21 21:06 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

deanchalk avatar Jun 08 '21 07:06 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

1.23.9 worked for me! Thank you!

angar4ik avatar Jun 08 '21 13:06 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

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

nitrospaz avatar Jun 09 '21 02:06 nitrospaz

Could you all verify if this is what you're running into: https://github.com/OmniSharp/omnisharp-vscode/issues/4573

Specifically the mentioned NRE in the OmniSharp log: image

NTaylorMullen avatar Jun 09 '21 03:06 NTaylorMullen

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

ghost avatar Jun 09 '21 13:06 ghost

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

Xeevis avatar Jun 11 '21 11:06 Xeevis

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)

jtsom avatar Jun 25 '21 16:06 jtsom

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

ronascentes avatar Jun 30 '21 16:06 ronascentes

It seems the tracking work is here: #33858

ronascentes avatar Jun 30 '21 16:06 ronascentes

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.

lucianotres avatar Aug 08 '23 15:08 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.

Same for me.

andrejpanjan avatar Aug 10 '23 07:08 andrejpanjan

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

blackshot avatar Sep 09 '23 00:09 blackshot

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.

etkramer avatar Sep 09 '23 06:09 etkramer

tagging @davidwengier for a Razor issue

dibarbet avatar Sep 12 '23 02:09 dibarbet

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.

https://github.com/dotnet/razor/pull/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 avatar Sep 12 '23 02:09 davidwengier

@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 razor-logs-verbose.txt - razor.trace set to Verbose

Most of the log entries mention that there's no project context. Can I select a project in VS Code in some way?

PeterDraex avatar Sep 16 '23 16:09 PeterDraex

Solution structure (stripped out all unnecessary context)

.
β”œβ”€β”€ WebIndemnizacionesVM.sln
β”œβ”€β”€ Compartido (ClassLib)
β”œβ”€β”€ DAS (ClassLib)
└── WebIndemnizacionesVM (Blazor Server)
    β”œβ”€β”€ App.razor
    β”œβ”€β”€ Program.cs
    β”œβ”€β”€ Shared
    β”œβ”€β”€ WebIndemnizacionesVM.csproj
    β”œβ”€β”€ _Imports.razor
    β”œβ”€β”€ appsettings.Development.json
    β”œβ”€β”€ appsettings.json
    └── Shared
        β”œβ”€β”€ MainLayout.razor
        └──  Componentes
            β”œβ”€β”€ NavMenu.razor
            └──  SideBar.razor

_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 using these versions image image

image

Razor-logs.log Razor-logs-verbose.log

and using these versions image image

image

Razor-logs-verbose-2.log

also... Why component syntax color are red in pre-release version?

UPDATE: added verbose logs

blackshot avatar Sep 16 '23 16:09 blackshot

@blackshot To set verbosity, open File -> Preferences -> Settings and search for razor.trace

PeterDraex avatar Sep 16 '23 17:09 PeterDraex

Thanks, i updated the comment with the verbose logs

blackshot avatar Sep 16 '23 17:09 blackshot

Thanks for the logs @blackshot

The good news is that the red component tags are fixed by https://github.com/dotnet/vscode-csharp/pull/6304, so should be in a release soon. The bad news is there is nothing in the logs that indicates any problem with Razor tooling, which means the NavMenu not being discovered is caused by something else. The _Imports.razor file seems to be being processed properly, because things like PageTitle are discovered fine, but for whatever reason when we ask Roslyn for the list of components that are available, NavMenu must not be in the list. You could try attaching the project.razor.vscode.json file, from the obj directory, but I suspect that will just show that the NavMenu component isn't in the list.

Is there anything "interesting" about NavMenu? An @inherits or @namespace directive perhaps? If you open NavMenu.razor in VS Code are there any errors reported in it? Also, in the file layout you included it looks like maybe the "Componentes" folder starts with a space? Or is that just a typo?

@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 avatar Sep 16 '23 22:09 davidwengier

@davidwengier Oh, I tried to make the logs cleaner (by restarting VS Code, and sending only the beginning) and it looks like the important parts got left out. I'll describe the issue and send new logs now.

My file Purchase.razor begins like this:

@page "/inventory/purchase"
@using System.Collections.Immutable
@using Microsoft.AspNetCore.Components.Web

@code {
    SupplierInInventoryPurchase[] suppliers = Array.Empty<SupplierInInventoryPurchase>();

    Layout.ContentTemplate.BreadcrumbItem[] breadcrumbs = new Layout.ContentTemplate.BreadcrumbItem[]
    {
        new Layout.ContentTemplate.BreadcrumbItem("Inventory"),
        new Layout.ContentTemplate.BreadcrumbItem("Purchase", "/inventory/purchase"),
    };

VS Code is reporting a problem:

The type or namespace name 'ContentTemplate' does not exist in the namespace 'Layout' (are you missing an assembly reference?)RoslynCS0234

When I locate my cursor after Layout.ContentTemplate. and press CTRL+Space, it shows general keyword suggestions, not relevant in the context. When I click on BreadcrumbItem or Layout and press F12, I get a message that no definition is found.

Here's a new log file, while the error was displayed, I tried bringing up the suggestions and going to definition. Is it helpful?

razor-logs2.txt

PeterDraex avatar Sep 16 '23 22:09 PeterDraex

Thanks for that info, thats very helpful. Unfortunately I'm not sure how helpful I can be. I can think of two possibilities:

  1. Given that your "type or namespace not found" error comes from a C# block, not a component, the most likely explanation is there are multiple things called "Layout" in scope, and Roslyn is binding to one you don't expect. eg, there is a Layout.razor in your client project, which would mean a type called "Layout", as well as the folder called "Layout" in AdminClient, which would create a namespace called "Layout". Is client referenced from AdminClient? And more importantly, is the "Client.Layouts" namespace included in the _Imports.razor in AdminClient?

  2. For some reason ContentTemplate.razor is not being discovered or compiled properly by Razor. I can see it in the logs, so it appears to be in the project correctly etc. Similar to the questions above, does it have errors in it if you open it? Anything in it that would affect compilation, like a @namespace or @inherits directive?

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 Purchase.razor open. That will show you the compiled C#, and you'll be able to see all of the using statements etc. that are in scope, which might help narrow it down. You could even try copying the code out of that window, and putting it in a new .cs file in the project, and maybe Roslyn will even highlight which parts are ambiguous, or not found. Potentially doing that with ContentTemplate.razor might be illustrative too, perhaps checking that the namespace declared in it is the one you expect.

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.

davidwengier avatar Sep 16 '23 23:09 davidwengier

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. The bad news is there is nothing in the logs that indicates any problem with Razor tooling, which means the NavMenu not being discovered is caused by something else. The _Imports.razor file seems to be being processed properly, because things like PageTitle are discovered fine, but for whatever reason when we ask Roslyn for the list of components that are available, NavMenu must not be in the list. You could try attaching the project.razor.vscode.json file, from the obj directory, but I suspect that will just show that the NavMenu component isn't in the list.

Is there anything "interesting" about NavMenu? An @inherits or @namespace directive perhaps? If you open NavMenu.razor in VS Code are there any errors reported in it? Also, in the file layout you included it looks like maybe the "Componentes" folder starts with a space? Or is that just a typo?

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

(adding some components to the context in order to understand NavMenu.razor)

.
β”œβ”€β”€ WebIndemnizacionesVM.sln
β”œβ”€β”€ Compartido (ClassLib)
β”œβ”€β”€ DAS (ClassLib)
└── WebIndemnizacionesVM (Blazor Server)
    β”œβ”€β”€ App.razor
    β”œβ”€β”€ Program.cs
    β”œβ”€β”€ Shared
    β”œβ”€β”€ WebIndemnizacionesVM.csproj
    β”œβ”€β”€ _Imports.razor
    β”œβ”€β”€ appsettings.Development.json
    β”œβ”€β”€ appsettings.json
    └── Shared
        β”œβ”€β”€ MainLayout.razor
        β”œβ”€β”€ LoginCascading.razor
        β”œβ”€β”€ Protegido.razor                 (used by NavMenu.razor [should be imported globally])
        └── Componentes
            β”œβ”€β”€ Badge.razor
            β”œβ”€β”€ Carta.razor
            β”œβ”€β”€ CartaMaterial.razor
            β”œβ”€β”€ CrearCuentaBancariaModal.razor
            β”œβ”€β”€ NavMenu.razor
            β”œβ”€β”€ SeleccionOrdenModal.razor
            β”œβ”€β”€ SideBar.razor
            β”œβ”€β”€ SpinnerHDI.razor
            └── VerAnotacionesModal.razor
            └── SideBarComps                (used namespace by NavMenu.razor imported inside it)
                β”œβ”€β”€ NavItem.razor           (used by NavMenu.razor)
                └── NavItemDropdown.razor   (used by 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.

image

Couldn't find "Protegido" neither which is imported in _Imports.razor image

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="#" @[email protected]/>
            </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="#" @[email protected]><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...

image

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...

image

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 Razor-logs-verbose-lost-references.log

blackshot avatar Sep 17 '23 02:09 blackshot

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

davidwengier avatar Sep 17 '23 03:09 davidwengier

Also, in the file layout you included it looks like maybe the "Componentes" folder starts with a space? Or is that just a typo?

it was a typo writting here in github, foldername is fine

blackshot avatar Sep 17 '23 03:09 blackshot

just in case is helpful, here are my enabled extensions at the moment bug happened.

$ code --list-extensions --show-versions | % { "code --install-extension $_" }

code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]
code --install-extension [email protected]

blackshot avatar Sep 17 '23 03:09 blackshot

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
Using dotnet configured on PATH
Dotnet path: C:\Program Files\dotnet\dotnet.exe
Activating C# + C# Dev Kit + C# IntelliCode...
waiting for named pipe information from server...
[stdout] {"pipeName":"\\\\.\\pipe\\70987ca1-88df-4050-a63c-98fd16286a13"}
received named pipe information from server
attempting to connect client to server...
client has connected to server
[Info  - 1:15:06 PM] [Program] Language server initialized
[Error - 1:15:16 PM] [LanguageServerHost] System.InvalidOperationException: Was not able to get hello world response from remote - line 39
   at Roslyn.Utilities.Contract.Fail(String message, Int32 lineNumber) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/Contract.cs:line 154
   at Microsoft.CodeAnalysis.LanguageServer.BrokeredServices.Services.HelloWorld.RemoteHelloWorldProvider.SayHelloToRemoteServerAsync(CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/Services/HelloWorld/RemoteHelloWorldProvider.cs:line 39
   at Microsoft.CodeAnalysis.LanguageServer.BrokeredServices.ServiceBrokerFactory.CreateAndConnectAsync(String brokeredServicePipeName) in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/ServiceBrokerFactory.cs:line 82
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 136
[Error - 1:16:36 PM] [LanguageServerHost] System.ArgumentException: Range={ Start={ Line=111, Character=37 }, End={ Line=900, Character=0 } }. text.Length=29910. text.Lines.Count=785
 ---> System.ArgumentOutOfRangeException: The requested line number 900 must be less than the number of lines 785. (Parameter 'Line')
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67
   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetTextSpan(LinePositionSpan span) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 78
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 298
   --- End of inner exception stack trace ---
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 298
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.ComputeSemanticTokensDataAsync(ClientCapabilities capabilities, Document document, Range[] ranges, ClassificationOptions options, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 85
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensHelpers.HandleRequestHelperAsync(IGlobalOptionService globalOptions, SemanticTokensRefreshQueue semanticTokensRefreshQueue, Range[] ranges, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs:line 50
   at Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens.SemanticTokensRangeHandler.HandleRequestAsync(SemanticTokensRangeParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensRangeHandler.cs:line 45
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 176
[Error - 1:16:36 PM] Request textDocument/semanticTokens/range failed.
  Message: Range={ Start={ Line=111, Character=37 }, End={ Line=900, Character=0 } }. text.Length=29910. text.Lines.Count=785
  Code: -32000 
[object Object]

PeterDraex avatar Oct 12 '23 06:10 PeterDraex

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

achobanov avatar Jan 15 '24 14:01 achobanov