Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Cannot open cshtml Files

I have a problem, which I cannot solve. I can't open every cshtml-File in a Visual Studio c# mvc project (whatever which project i tried). I get the following error Msg (I try to translate to English):

Object reference not set to an instance to an object

Google says, it may be a NullReferenceExeception. But it has nothing to do with my code, because first I can execute the project successfully and second the error occurs in every project (since today).

like image 631
Maermot Avatar asked Dec 08 '15 12:12

Maermot


People also ask

What file type is Cshtml?

What is a CSHTML file? A file with . cshtml extension is a C# HTML file that is used at server side by Razor Markup engine to render the webpage files to user's browser.


3 Answers

I just experienced the same issue. It just came out of nowhere, as you described. I even went through a 2 hour repair. That didn't fix it.

However, a coworker suggested this fix.

Visual Studio 2015 not syntax highlighting razor nor Intellisense

I had the same problem, the only fix so far is by resetting all user data (C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe /ResetUserData).

Now I am able to use the real default editing and I get good syntax highlighting again.

like image 108
mac10688 Avatar answered Oct 17 '22 01:10

mac10688


The solution that worked for me was from here

  1. Close VS
  2. Delete the content of %LocalAppData%\Microsoft\VisualStudio\15.0\ComponentModelCache
  3. Open VS

As suggested by @jamez14, if your are using a different version of Visual Studio, just change 15.0 in the path to the version you have.

like image 27
Miro J. Avatar answered Oct 17 '22 01:10

Miro J.


I faced the following issue.

ISSUE: All .cshtml were not opening in visual studio 17 community.

REASON: Accendently shutdown laptop by power off button while files were open in visual studio.

I tried all the above solutions but none worked.

Following solution worked for me.

Repaired Visual Studio using Visual Studio Installer.

like image 7
TarakPrajapati Avatar answered Oct 17 '22 00:10

TarakPrajapati