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条回答
做自己的国王
2楼-- · 2020-01-25 13:24

I was getting an exception every time I tried to create a "new" project.

My solution was:

  1. Go menu ToolsExtensions and Updates

  2. Check the "Updates" link... There was an update to Microsoft ASP.NET and Web Tools. Install it.

That fixed it for me.

查看更多
不美不萌又怎样
3楼-- · 2020-01-25 13:24

I was getting similar error in VS2017 while trying to publish my solution to Azure.

This algorithm helped me to resolve it:

  1. Close VS2017
  2. Open C:\Users{your user name}\AppData\Local\Microsoft\VisualStudio\ folder
  3. Rename 15.0_08edcd83 folder
  4. Start VS
  5. Publish works fine!

Note that this will remove your Visual Studio's recent files / projects from it's history and also linking to MS account.

This method is slightly different from the Top answer. Here you don't have to delete other folders except renaming abovementioned one.

查看更多
对你真心纯属浪费
4楼-- · 2020-01-25 13:29

For me, ASP.NET 5 is not yet required, I removed update, and then reinstalled ASP.NET 4.5. It's a bit tricky:

  1. Removed from control panel "Microsoft ASP.NET 5 RC1 Update1". After that, you will no longer open ASP.NET MVC projects
  2. Then I changed the installation of "Microsoft Visual Studio Professional 2015", clicked "Modify", and selected "Microsoft Web Developer Tools"

No longer follow the notification of update in Visual Studio 2015!!!

查看更多
倾城 Initia
5楼-- · 2020-01-25 13:30

It's recommended to try any or all of the following:

  • Restart Visual Studio

  • Try Running As Administrator (right-click Visual Studio and choose "Run As Administrator")

  • Check for any updates for Visual Studio (download and install them if any are available)

  • Try opening a different solution / project

If problems persist, you might try the following options:

  • Restart your local machine

  • Attempt to reset Visual Studio to System Defaults (this can be done from the options within Visual Studio)

  • Attempt to repair your Visual Studio installation

查看更多
时光不老,我们不散
6楼-- · 2020-01-25 13:30

After trying the top answer, I found that you must also restart the computer. The error may be part of a git issue as well where restarting your computer will reset.

查看更多
Rolldiameter
7楼-- · 2020-01-25 13:34

I have been fighting with this during the whole weekend. But it's pretty easy to do it. What I did was to click on repair rather than uninstall. After repairing, I clicked on restart directly. After that, everything is working perfectly. You should try this, may be it can work also for you!!!

查看更多
登录 后发表回答