Search code examples
blazorcomponentsblazor-server-side

Blazor Server App Not recognizing more than one component


Visual Studio 2022.

Blazor Server app.

Created a Components folder under my WebApp folder. Created a .razor compnent - a dialog box. Reference this dialog box, no issues, works as expected.

Now, when I create another .razor component in the Components folder, or anywhere else, VS 2022 intellisense fails to recognize the other component. Asking for a @using at the beginning of the page.
I've tried copying the current, working component but no luck. Also, if I rename the working component file, it ceases to function, however, I do not find or recall ever registering or including the first component anywhere.

I'd rather not just have one component for all of my very different dialog needs.


Solution

  • This is well known issue in Visual Studio that intellisense fails to recognize components or razor syntax is not working. There have been similar posts about this topic for example : Blazor broken syntax coloring

    They sometimes post patches that address this problem, but this bug still happens. It's hard to tell if the issues are connected. However you should be able to still build the project despite visual studio showing errors.

    Here is what I usually do when it happens to me (may not work for you).

    1. Open Project Configuration file and remove all stuff in item groups that refers to your .razor files .
    2. Clean Solution.
    3. Exit visual studio.
    4. Open your solution folder and remove .vs hidden folder.
    5. In each project folder remove obj and bin folder.
    6. Open visual studio and rebuild.

    I hope this steps will help you.