Blazor and Visual Studio's Intellisense - some Blazor component references show as false errors until you click on the file

Viewed 683

When I open my Blazor solution in Visual Studio, Intellisense will show false errors for references to Blazor components, and will successfully compile.

For example, in many of my classes I inject ILogger<BlazorComponent> that takes a component to log about, in this case, my Details.razor component:

public partial class DetailsBase : ComponentBase
{
   [Inject]
   protected ILogger<Details> Logger { get; set; }
   
   // etc etc... 
}

However, Intellisense always shows a not found error for Details. It will compile successfully but the false error will remain, until you navigate to that particular file - Details.razor in this case - and Intellisense picks it up.

These false errors clutter up my debug window and I'd like to stop them without constantly having to click to go to the file to get it recognised by Intellisense.

Is there some kind of setting I can enable that makes sure Intellisense checks these files? or anything that plays nicer with Blazor than Intellisense?

3 Answers

I ran into this same issue but couldn't find any relief on the interwebs. I had deleted a .cshtml.cs file that I accidentally added, and couldn't get rid of the IS errors. Deleting .vs, obj, bin, restart VS, nothing.

However, I finally found a solution after a few hours of digging. To get rid of the phantom errors I closed Visual Studio, deleted the files in the following folder, and then re-opened the solution: C:\Users\<Username>\AppData\Local\Temp\VSFeedbackIntelliCodeLogs\Suggestions\

Try disabling the experimental razor editor. It did similar weird things on my end

Looks like @PerryQian-MSFT's suggestion of deleting vs folder has done the trick.

I haven't noticed any issues for a day now.

Related