2

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.

2
  • This needs details and exact error messages. Best is posting a minimal reproducible example Commented Feb 12, 2024 at 21:11
  • @ℍℍ The issue is, when I build a project from scratch, all the components behave correctly. Accepted answer fixed me up nice. Commented Feb 14, 2024 at 21:24

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Another good tip is don't copy or rename Razor files in Visual Studio. Do it in File Explorer.
"Have you tried turning it off and on again?"
I have also used this method with success, everything else has failed. I have not removed the .vs hidden folder though, so I am not sure that is necessary. Adding @usings does nothing, not in the parent component or in the _Imports file.
2

This has been driving me bonkers too!! I got lucky and this worked for me.

  1. Right Click on Project -> Unload Project
  2. Right Click again on Project -> Reload Project

That's it.. hoping everyone has similar success.. Blazor rocks :)

Comments

0

Dragging the component into the root folder of the project, instead of (for example) /Pages/Users/Login.razor, fixes the green wriggles in App.razor.

Sometimes supplying the namespace in full works:

<BookStoreApp.Blazor.Server.UI.Pages.Users.Login></BookStoreApp.Blazor.Server.UI.Pages.Users.Login>
<BookStoreApp.Blazor.Server.UI.Pages.Users.LoginTest ></BookStoreApp.Blazor.Server.UI.Pages.Users.LoginTest>

Sometimes, trying to create a ctor (tab, tab) fails for one of the component, illustrating the problem.

I tried to add explict @namespace in the component and @using in App.razor, but no improvment.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.