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

3

4

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?

Incalescent answered 12/1, 2021 at 11:27 Comment(4)
I have observed the same behavior; to me it looks like a defect in Visual Studio handling of Blazor code. Two things that may help some: 1) close all the open windows in the solution. 2) use code-behind for c# instead of putting the c# code directly into the .razor file.Cobalt
Try to close VS, and then delete .vs hidden folder under the solution folder and then restart your project to check whether the behavior.Zigzagger
mb1231,did this work?Zigzagger
@PerryQian-MSFT yes it seems to have done the trick. It hasn't happened since yesterday so will mark as fixed. Cheers!Incalescent
I
1

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

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

Incalescent answered 15/1, 2021 at 11:39 Comment(0)
M
12

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\

Monti answered 16/2, 2021 at 6:22 Comment(3)
I'm a newbie, so please forgive me if I'm way off base... I think what's happening is that the .cshtml.cs file gets deleted, but Intellisense doesn't recognize it's gone and continues to serve up errors using some cached values stored on disk. The offending files appear to be in the subfolders of \Suggestions, specifically: ...\Suggestions\<guid>\output\versions\<classname>.cshtml.g.#.csMonti
your solution cleaned-up all of the wrongly claimed errors in my solution! Finally solution that worked. Actually, I removed all folders starting with VS in temporary folder.Wales
There was no /Suggestions folder for me. However there were a lot of log files. After removing those my issue was resolved.Valley
S
1

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

Suu answered 12/1, 2021 at 16:23 Comment(2)
didn't know it existed lol - sadly it was disabled by default for meIncalescent
Bummer, I hoped that would be it. Try closing Vs then deleting the bin and obj folders tooSuu
I
1

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

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

Incalescent answered 15/1, 2021 at 11:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.