3

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?

mb1231
  • 308
  • 3
  • 16
  • 2
    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. – Jason D Jan 12 '21 at 17:50
  • 1
    Try to close VS, and then delete `.vs` hidden folder under the solution folder and then restart your project to check whether the behavior. – Mr Qian Jan 13 '21 at 07:52
  • mb1231,did this work? – Mr Qian Jan 15 '21 at 09:43
  • @PerryQian-MSFT yes it seems to have done the trick. It hasn't happened since yesterday so will mark as fixed. Cheers! – mb1231 Jan 15 '21 at 11:38

3 Answers3

6

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\

rovert
  • 61
  • 3
  • 2
    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\\output\versions\.cshtml.g.#.cs – rovert Feb 16 '21 at 06:24
  • 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. – Alex Oct 20 '21 at 15:09
  • 1
    There was no /Suggestions folder for me. However there were a lot of log files. After removing those my issue was resolved. – Joost00719 Nov 14 '22 at 11:22
1

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

rdmptn
  • 5,413
  • 1
  • 16
  • 29
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.

mb1231
  • 308
  • 3
  • 16