Search code examples
asp.net-mvcvisual-studiorazor

Why is razor code in VS19 not highlighting in .cshtml file?


I'm using Visual Studio 2019, v16.11.8 Preview 1.0 to work on MVC projects. At some point my razor code stopped appearing highlighted in .cshtml files, making HTML and C# difficult to tell apart. This is how the code looks now: enter image description here

I've checked over the color settings for razor code by going to Tools -> Options -> Environment -> Fonts and Colors -> HTML Razor Code Background, but this and the other related settings looked fine. I've also tried restarting VS and the machine itself.

What is the cause of this and how can I fix it?


Solution

  • Found the issue. An experimental Razor editor is enabled by default in the preview. One of the known issues relates to the coloring.

    To disable the experimental editor go to Tools > Options > Preview Features and scroll down to uncheck Enable Experimental Razor editor (requires restart). Click Ok and restart your VS.

    enter image description here