“Object Reference Not Set to An Instance of An Object” is most commonly known as a NullReferenceException code error, which occurs when you try to access an object that has a null reference. This error can also be generated in Visual Studio when projects that require administrative permission are not granted.
Other contributing factors for this error include issues with extensions, particularly those of the ASP.NET
frameworks. The Visual Studio IDE also is reported to face issues in touch-enabled Windows devices.
We will address all these issues throughout this article and help you resolve the Object reference error in Visual Studio.
Fixes for Visual Studio Object Reference Not Set to An Instance of An Object
The first thing to do is to verify the codes. The “Object Reference Not Set to An Instance of An Object” error occurs when a variable is used but not initiated. If an object is set to null, then no function can be applied to it. Assign a value to the string or an object and then see if it works for you.
The next thing you can do is Restart Visual Studio and also your local machine. If this issue has been triggered by some glitches in the system or the IDE, this may fix the issue.
Run Visual Studio as an Administrator
To open some of the projects on Visual Studio, you might need administrator permissions. The Visual Studio IDE does not launch on Windows with elevated permissions automatically. In such a case, you must do it manually.
- Click on the start menu and search for Visual Studio.
- Right-click on it and select Run as Administrator.
- Finally, check if you get the error now.
Update Extensions
This error might also appear because of the IDE extensions that you use to add different features to Visual Studio. These extensions might have corrupted or become outdated; hence, updating these is reported to have fixed the issue for many users.
The extensions related to the ASP.NET
seems to have caused the problem for most of the users. Here’s how to update this extension.
- Open Microsoft Visual Studio.
- Go to the Extensions tab.
- Select Manage Extensions.
- Go to the Updates Section from the left panel.
- See if you have any pending updates. Generally, the updates for the Microsoft
ASP.NET
and web tools solve this issue.
Add Frameworks
If you are trying to create a project under ASP.NET
, and getting the Visual Studio Object Reference Not Set to An Instance of An Object error, it must be possible that some packages related to this application framework are yet to be installed. If this has triggered the issue in your case, you can install these remaining packages and resolve the problem.
- Click on the Tools tab.
- Select Get tools and features.
- Select the ASP.NET and web development framework.
- From the installation details panel, check all the Frameworks and tools under it.
- Click on Modify.
- It will start downloading the packages for the
ASP.NET
application framework.
Disable Touch Keyboard and Handwriting Panel Service
If You are running Visual Studio on a Windows 10 machine that is touch-enabled, it is very likely that you will face an error such as this one. To overcome this, you can disable the Touch keyboard and handwriting service from the Windows Services.
- Press Windows Key + R, type
services.msc
and hit enter. - Under the list of services, find the Touch keyboard and Handwriting Panel Service and open it.
- Set the Startup type to Disabled and Click on Apply to save the changes.
Update Touch Screen Drivers
It is seen that on Windows 10 version 1803, the multi-touch gesture doesn’t seem to be functioning well. This might also contribute to this issue with Visual Studio. If you are using version 1803 or below, it is recommended that you update the system to a newer stable release.
If you do not want to perform a system update, updating the drivers also could do the job.
- Press Windows Key + X, and open the Device Manager.
- Expand the list of devices under the Human Interface Devices.
- Find the HID-complaint touchscreen device and right-click on it.
- Select Update Drivers.
- Choose Search automatically for Drivers and follow the prompts to update the touch screen drivers.
Delete Component Model Cache
Whenever you install any new extensions, there is a high chance for the component model cache to get corrupted. This can generate the issues as this one.
However, if you delete its directory completely, Visual studio will rebuild it and give a fresh start to the component cache, solving many issues of Visual Studio.
- Open the File explorer and go to this directory. The Drive letter will be different for the users who have set the System partition drive other than
C:
.C:\Users\%userprofile%\AppData\Local\Microsoft\VisualStudio
- Open the Folder named with the Visual Studio version (For instance, 17.0_4b4bc243).
- Locate the
ComponentModelCache
folder and delete it. - Now, navigate to the directory:
C:\Users\%userprofile%\AppData\Local\Microsoft\VSCommon
- Rename the folder
VSCommon
toVSCommon.old
- Finally, Restart Visual Studio.
- Finally, Restart Visual Studio.
Update Visual Studio
Updating Visual studio will give you better improvement in the IDE, new features and also bug fixes. For issues like this and others on the IDE, it’s always good to keep it updated. Users also can set up auto-updates for automatically downloading new update roll-outs.
To perform manual updates, follow these steps.
- Open the Visual Studio.
- Go to the Help tab.
- Select Check for Updates.
- The Visual Studio installer will then launch and then start searching for the available updates. The installer will show it under the currently installed version if it finds one.
- Click on Update and follow the prompt.