14

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.

Community
  • 1
  • 1
SHM
  • 1,896
  • 19
  • 48
  • 1
    Alternatively, it might have something to do with which code was executing at the time, so you should show us _the complete exception_. – John Saunders Apr 30 '15 at 05:05
  • 2
    why are you talking about code? did you read the question? it is clearly saying "can not open cshtml file by clicking on them" there is no intellitrace for that :D – SHM Apr 30 '15 at 05:12
  • 1
    Is there no code in Visual Studio 2013? – John Saunders Apr 30 '15 at 05:13
  • Does the modal dialog (I assume that's what's happening here?) have a "Details" button, or anything to that effect? I think that's what John is asking for. – Matthew Haugen Apr 30 '15 at 05:20
  • no details button. i have added an image. – SHM Apr 30 '15 at 05:25
  • Please post your complete web.config file, any error in this file will cause this exception. – Stéphane Bebrone May 05 '15 at 05:40
  • It's probably an error in one of the 3rd parties installed in your Visual Studio. VS is not protected against rogue or buggy extensions. You should try to remove them ... one by one. – Simon Mourier May 05 '15 at 06:19
  • i have been using current extensions for about a year, how can it blow at once? i just have Xamarin.Visual studio installed. :D – SHM May 05 '15 at 06:33
  • install Update 4 of Visual Studio 2013. Download Link http://www.visualstudio.com/en-us/news/vs2013-update4-rtm-vs.aspx – Abdul May 06 '15 at 13:04
  • @Hassan try this SO answer https://stackoverflow.com/a/19576300/1298308 – Aminul May 11 '15 at 08:22

10 Answers10

10

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.

adinas
  • 4,150
  • 3
  • 37
  • 47
2

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

Brian from state farm
  • 2,825
  • 12
  • 17
2

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.
cmcquillan
  • 696
  • 4
  • 12
2

If trying to open an asp.net mvc 4 project in your Visual Studio 2013 then review the web.config edit <appSettings> as following

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

Hope this helps :)

Aminul
  • 1,738
  • 2
  • 24
  • 42
1

Do you have any extensions installed? Maybe one of them is throwing this error.

Can you try starting vs.net in SafeMode and check if the problem still occurs? If yes, try to disable your extensions one by one until it disappears.

devenv.exe /SafeMode

Other solution, double check that your entire web.configis valid (not only the appSettings section). It cannot contains duplicate, invalid child, not well formed XML...

Stéphane Bebrone
  • 2,713
  • 17
  • 18
  • i have tried your solution, it dose not work. thanks any way. my web.config is ok because i have many other mvc projects on my machine and all of them have same problem. – SHM May 05 '15 at 05:51
1

It might be a problem with the version of Javascript you are using. I had a similar problem where i just uninstalled and reinstalled the latest nuget packages. Then i made sure the right versions listed in web.config.

Nilmag
  • 553
  • 6
  • 26
1

I had this funny error, this worked for me then..

try 'Unload project' and reloading again by right clicking on project name in solution explorer

ThePravinDeshmukh
  • 1,823
  • 12
  • 21
1

In my visual studio 2015 resolved by deleting all files in the% LocalAppData% \ Microsoft \ VisualStudio \ 14.0 \ ComponentModelCache

Thanks...

0

Basically, make sure your web.config isn't corrupt.

I got this after inserting "&" instead of "amp;" into an app setting.

Dunc
  • 18,404
  • 6
  • 86
  • 103
0

Try this; In my visual studio 2015 resolved by deleting all files in the% LocalAppData% \ Microsoft \ VisualStudio \ 14.0 \ ComponentModelCache it's work.

bazad
  • 1