blazorvisual-studio-2022

VS2022 problem Blazor pages with code colors


I work on a Blazor solution with 4 small projects on it. Basically grids and edit forms with all pages with limited code, usually less than 1k lines. I use VS2022 and always update to the latest version but recently when I am working on a page and add code to the .razor page, (I always use the razor/cs class combination except when it is very little code) the color coded is gone (sometimes, not always). The component initial tag change from green to blue and everything in between until the closing tag becomes white letters. There is no more intellisense assistance. I have tried clean, rebuild, close and reopen the page but the only thing that works all the times is to close the solution, close VS2022, delete the "bin" and the "obj" folders of the default app and them it works for awhile until next time. I notice that this can happen if there is error in the code but most of the times there isn't and if the error is corrected it doesn't restore the colors. I compile and run the app and it works perfectly and the razor page still doesn't show the correct colors. This is really annoying and is affecting my production tremendously. Should I try to uninstall it and do a fresh new install ? I haven't done it cause I believe that this is done when there is a new updated version, but I am not sure.


Solution

  • I strongly advice you to use the preview version of Visual Studio until next november, when a stable Visual Studio major version is released. It works pretty fine for me. I know these problems you have very well.

    But for most people facing this problem:

    1. Clean Solution
    2. Close Visual Studio.
    3. Update Visual Studio to latest version
    4. Delete the bin and obj folders of all of your projects in the solution.
    5. Open Visual Studio.
    6. Enjoy your intellisense and nice colors of your razor editor until the next .NET or major Visual Studio upgrade.

    These kind of problems usually happens when you upgrade your .NET version.

    Edit: Also be careful when you switch e.g. branches with different / changing .NET versions in the solutions or projects.