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:16

Restarting Visual Studio did it for me. On the next run, it displayed a "Scanning new and updated MEF components ..." and then it executed normally.

It seems to be related to Windows update somehow, although I don't have proof.

查看更多
狗以群分
3楼-- · 2020-01-25 13:18

The solution to the issue when i had this earlier today was that there was an additional set of tags bolted on the end of my Web.config. Once removed the functionality returned.

查看更多
Summer. ? 凉城
4楼-- · 2020-01-25 13:18

Problem: My VS 2015 was throwing up error after I installed SSDT. Whenever I clicked on Tools >> Extensions and Update it was throwing "Object reference not set to an instance of an object" error. When I tried to open a solution it threw some provider not set correctly.

Solution: After many hours of research trying out all the solutions previously mentioned by others didn't solve my problem. Every time the error popup was pointing to check the ActivityLog.xml. But I was ignoring it. After hours of frustration I decided to read the error carefully and looked into ActivitLog.xml and found that it was looking for "Could not load file or assembly 'System.Collections.Immutable, Version=1.1.37.0". So I just started searching for this assembly and stumbled upon this link https://sergeytihon.com/2015/12/01/how-to-restore-viual-studio-2015-after-update-1-dependency-dance/ and followed the steps there, which fixed my issue.

Went into %LOCALAPPDATA%/Local\Microsoft\VisualStudio\14.0\devenv.exe.config and searched for "System.Collections.Immutable" and change newVersion from 1.1.36.0 to 1.1.37.0

Final config should look like this

<dependentAssembly>
 <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
 <bindingRedirect oldVersion="1.0.27.0-1.1.65535.65535" newVersion="1.1.37.0"/>
</dependentAssembly>
查看更多
狗以群分
5楼-- · 2020-01-25 13:19

In my case (not necessarily be the solution for you, but it may be helpful for someone), the solution was:

  1. Go menu ToolsExtensions and Updates

  2. Select the Online tab from the right panel

  3. Search for the words web tools, and then select Microsoft ASP.NET and Web Tools and install it.

In my case, this was missing from my computer because of a lot of repairing operations for Visual Studio.

查看更多
Animai°情兽
6楼-- · 2020-01-25 13:22

Delete %LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache and restart Visual Studio.

Alternatively, use the Clear MEF Component Cache extension.

查看更多
三岁会撩人
7楼-- · 2020-01-25 13:24

In the hopes it might narrow things down/help someone, I did an investigatory approach. For me, I initially moved the folder at C:\Users\{user}\AppData\Local\Microsoft\VisualStudio to My Documents and allowed Visual Studio to re-create it by re-launching it. This removed the errors. So I moved everything back, one-by-one, and restarted Visual Studio each time until I discovered the culprits. These folders were fine to move back in:

  • 1033 (overwrote the auto-generated copy with old)
  • Designer (was in my old copy, not initially re-created when I re-launched VS, copied it back in)
  • Extensions (overwrote the auto-generated copy with old)
  • ImageLibrary (overwrote the auto-generated copy with old)
  • Notifications (overwrote the auto-generated copy with old)
  • STemplate (was in my old copy, not initially re-created when I re-launched VS, copied it back in)
  • VTC (was in my old copy, not initially re-created when I re-launched VS, copied it back in)

These files were fine to move back in/overwrite the auto-generated ones:

  • ApplicationPrivateSettings (was in my old copy, not initially re-created when I re-launched VS)
  • ApplicationPrivateSettings.lock (overwrote the auto-generated copy with old)
  • vspdmc.lock (overwrote the auto-generated copy with old)

These files were fine to move back in. Each was in my old copy, and not initially re-created when I re-launched VS:

  • .NETFramework,Version=v4.0,Set=Framework,Hash=C958D412.dat
  • .NETFramework,Version=v4.0,Set=RecentAssemblies,Hash=0.dat
  • .NETFramework,Version=v4.5,Set=Extensions,Hash=75EAE334.dat
  • .NETFramework,Version=v4.5,Set=Extensions,Hash=497525A2.dat
  • .NETFramework,Version=v4.5,Set=Framework,Hash=5AE9A175.dat
  • .NETFramework,Version=v4.5.2,Set=Extensions,Hash=24CEEB0D.dat
  • .NETFramework,Version=v4.5.2,Set=Extensions,Hash=72AE305.dat
  • .NETFramework,Version=v4.5.2,Set=Extensions,Hash=ADF899D7.dat
  • .NETFramework,Version=v4.5.2,Set=Framework,Hash=D8E943A2.dat

These caused problems - delete these files and re-launch VS to allow it to re-create them:

  • ComponentModelCache - When I overwrote this folder's contents with my old ones (4 files: MS.VS.Default.cache, .catalogs, .err, .external), this gave me all of the errors I had gotten before about not being able to load packages when loading my project, and the "object reference not set to an instance of an object" error when trying to close VS.
  • devenv.exe.config - same as ComponentModelCache
  • .NETFramework,Version=v4.0,Set=Extensions,Hash=6D09DECC.dat - causes error output from the JavaScript Language Service, complaining of missing js files
  • .NETFramework,Version=v4.0,Set=Extensions,Hash=9951BC03.dat - causes error output from the JavaScript Language Service, complaining of missing js files
  • .NETFramework,Version=v4.5.2,Set=RecentAssemblies,Hash=0.dat - causes error output from the JavaScript Language Service, complaining of missing js files

These are the errors from those last .NETFramework files (which I do not get if I do not add them back in):

01:10:11.7550: Referenced file 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\JavaScript\References\libhelp.js' not found.
01:10:11.7550: Referenced file 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\JavaScript\References\sitetypesWeb.js' not found.
01:10:11.7550: Referenced file 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\JavaScript\References\domWeb.js' not found.
01:10:11.7550: Referenced file 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\JavaScript\References\underscorefilter.js' not found.
01:10:11.7550: Referenced file 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\JavaScript\References\showPlainComments.js' not found.

I might just need to re-install/repair the JavaScript Language Service plug-in, so it might be un-related. But definitely devenv.exe.config and ComponentModelCache need to go to correct the "object reference not set to an instance of an object" error.

查看更多
登录 后发表回答