Visual Studio error “Object reference not set to a

2020-01-25 12:29发布

After installing the ASP.NET and Web Tools 2015 (RC1 update 1) I get the following error within ASP.NET MVC 4 projects when opening *.cshtml files:

Object reference not set to instance of an object

Enter image description here

I get the same error message even if I start a new ASP.NET MVC 4 project and try to open a *.cshtml file there.

I'm using Visual Studio 2015

18条回答
Emotional °昔
2楼-- · 2020-01-25 13:08

Goto windows+R and type %temp% and hit enter. delete the temp folder and files and then try opening the same

查看更多
孤傲高冷的网名
3楼-- · 2020-01-25 13:09

I solved it doing

run devenv /resetuserdata

in this path:

[x64] C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE

I assume that in x86 it works in this path:

[x86] C:\Program Files\Microsoft Visual Studio 14.0\Common7\IDE
查看更多
放荡不羁爱自由
4楼-- · 2020-01-25 13:11

Maybe this helps:

  1. Delete the contents from the following folders:
    1. C:\Users\%userprofile%\AppData\Local\Microsoft\VisualStudio
    2. C:\Users\%userprofile%\AppData\Local\Microsoft\VSCommon
  2. Sometimes, you need to go to:
    1. [x64] C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
    2. [x86] C:\Program Files\Microsoft Visual Studio 14.0\Common7\IDE

and run devenv /resetuserdata.

Expect, that all of your user settings such as Visual Studio layout, linked Microsoft account or start page might disappear.

查看更多
劫难
5楼-- · 2020-01-25 13:13

Delete bin and obj folders in all projects of that solution.

Seems like those folders were having old files generated by some older version of visual studio, which are not compatible with new version of visual studio.

查看更多
一纸荒年 Trace。
6楼-- · 2020-01-25 13:14

I was getting this exception every time I created a "new" project.

My solution was:

  • Go menu Tools ? Extensions and Updates
  • Not check the "Updates" link...search "asp.net". There was an update to Microsoft ASP.NET and Web Tools. Get it as AspNetWebFrameworksTools2015_KB3137909.exe and install it.

That fixed it for me.


Unfortunately, I ran into another exception:

"Exception has been thrown by the target of an invocation"

I disabled the FIPS setting Enabled DWORD value to zero.

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy]
Enabled=dword:00000000 And All fixed.
查看更多
兄弟一词,经得起流年.
7楼-- · 2020-01-25 13:15

For me,

  1. I ended the process in Windows Task Manager: VsHub.exe.
  2. Restarted Visual Studio.

After that, everything works like a charm again!

查看更多
登录 后发表回答