Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object reference not set to an instance of an object when opening cshtml files in visual studio 2013

When I try to open .cshtml files in Visual Studio 2013 I get this error:

enter image description here

Object reference not set to an instance of an object

I have tried the solution given here but it did not work. Here is my appsettings section in the web.config:

<appSettings>
   <add key="Port" value="25" />
   <add key="webpages:Version" value="3.0.0.0" />
   <add key="webpages:Enabled" value="false" />
   <add key="ClientValidationEnabled" value="true" />
   <add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>

i do not think that the problem is about this particular project, because all my other MVC projects have same problem.

like image 787
SHM Avatar asked Apr 30 '15 04:04

SHM


3 Answers

I had exact same issue in Visual Studio 2015.

I solved it by deleting all files in %LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache

(the 14.0 folder with be different depending on VS version installed I think.

like image 127
adinas Avatar answered Nov 10 '22 04:11

adinas


Try creating a new project and add a cshtml file. Do not make any other changes and do not use any templates you created. If the issue still occurs when you attempt to open this file, something is wrong with your system.

In this case you could attempt to get more information from VS by enabling the log. Detailed link to enable log

Simple example

Devenv /log

like image 21
Brian from state farm Avatar answered Nov 10 '22 03:11

Brian from state farm


Here's a relatively weird process that has worked for me before:

  1. Open Visual Studio, open your original project.
  2. Open a second copy of visual studio
  3. In second Visual Studio. Go to Debug -> Attach to Process and attach to the first visual studio instance.
  4. Do whatever it was you were doing in the first Visual Studio instance that made the exception occur.
  5. Analyze the names of classes/methods in the stack trace to find the buggy extension or plug-in.
  6. Uninstall offending piece of software.
like image 2
cmcquillan Avatar answered Nov 10 '22 03:11

cmcquillan