Quite often people stumble into same problems again and again, and getting a NullReferenceException
is the one that occurs most frequently, and frankly, can be quite annoying. This problem happens when
writing brand-new ASP.NET MVC code, such as controllers or views, but also when modifying existing
code that used to work just fine, but somehow suddenly got broken. Here I want to show you why these
exceptions happen and how to fix them, so you can stop wasting your time and do more of the
programming that you actually enjoy.
Not sure where should those try
…catch
blocks go in your code? Learn how to deal with various
types of exceptions in your apps: Where should you put “try … catch” statements in your C#
code
What is NullReferenceException and where can it happen?
NullReferenceException is exactly what it says — it is thrown by .NET Runtime
when your code tries to access properties or call methods using empty, or null,
reference. It sounds obvious and trite, but finding a place in your code where
things went haywire may take some time.
NullReferenceException in .cshtml Razor views
Let’s say you have a UserProfile.cshtml page that displays “Industry” selection
drop down list for a logged in user (to put a dropdown on a form see my other
article):
@model UserProfileModel
<div class="form-group">
@Html.LabelFor(m => m.Industry)
@Html.EnumDropDownListFor(model => model.Industry,
Model.Industries,
"- Please select your industry -",
new { @class = "form-control" })
</div>
and when you hit this page you see the following exception:
Server Error in ‘/’ Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 27: <div class="form-group">
Line 28: @Html.LabelFor(m => m.Industry)
Line 29: @Html.EnumDropDownListFor(m => m.Industry,
Line 30: Model.Industries,
Line 31: "- Please select your industry -",
Source File: c:[…]ViewsProfileUserProfile.cshtml Line: 29
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] ASP._Page_Views_Profile_UserProfile_cshtml.Execute() in c:...ViewsProfileUserProfile.cshtml:29 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +271 [... some lines deleted ...] System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +932 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +188
Believe me or not, this problem trips people over most often. The reason for this exception
is that no model is being passed to the view from the controller’s action:
public ActionResult UserProfile() {
var userModel = GetLoggedInUser();
//
// … some more super-serious business logic in here ...
//
return View(); // <-- HERE'S THE PROBLEM!
}
That’s why when the view is being rendered, Model
variable inside of .cshtml
points to null
, and trying to access null.FirstName
obviously throws a brand
spanking new NullReferenceException
. To fix this need to pass an instance of
the model to the View() call:
public ActionResult UserProfile() {
var userModel = GetLoggedInUser();
//
// … some more super-serious business logic in here ...
//
return View(userModel); // <-- JUST PASS THE MODEL HERE, TOO EASY!
}
NullReferenceException when working with database entities
This is a second most-common problem — when loading entities from a database,
you cannot always be sure whether an object you’re trying to load or one of its
linked entities exists. Say there’s an optional Address
object that
UserProfile
object can be linked to. If you do the following in your code,
you’ll get a NullReferenceException when Address
is missing:
public int GetUserPostCode(int userId) {
var user = GetUserFromDb(userId);
return user.Address.PostCode;
}
In which case the following exception will blow your call stack right up:
Server Error in ‘/’ Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 55: public int GetUserPostCode(int userId) {
Line 56: var user = GetUserFromDb(userId);
Line 57: return user.Address.PostCode;
Line 58: }
Source File: c:…ControllersProfileController.cs Line: 57
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] App.Controllers.ProfileController.ViewProfile() in c:...ControllersProfileController.cs:57 lambda_method(Closure , ControllerBase , Object[] ) +101 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +59 ... some lines skipped... System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +932 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +188
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34212
To fix this exception, you need to retrieve data in a safe manner — by checking all the reference
types first and avoiding dangerous assumptions that related objects are always going to be present:
public int? GetUserPostCode(int userId) { // Notice that function returns nullable int now
var user = GetUserFromDb(userId);
if (user != null && user.Address != null) { // This check will help to avoid NullReferenceExceptions
return user.Address.PostCode;
}
return null;
}
NullReferenceException when calling methods on null
Similarly, calling any functions on a null reference will result in
NullReferenceException. Say you are building an auction site, where users can
add photos to their listings. There’s class called ‘Listing’ that has a
collection of ‘Photos’, and you want users to be able to submit new listings
along with the photos in the following manner:
[HttpPost]
public ActionResult NewListing(ListingModel model) {
var newListing = new ListingDBObject {
Price = model.Price,
Title = model.Title,
ContactNumber = model.ContactNumber
}
foreach (var photo in model.Photos) {
newUser.Photos.Add(new PhotoDBObject { // <- THIS WILL BLOW UP!
BinaryData = photo.Data;
});
}
//...here goes code that saves new listing to the database
}
Again, you’ll get a brand new NullReferenceException with the following stack
trace:
Server Error in ‘/’ Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 25:
Line 26: foreach (var photo in model.Photos) {
Line 27: newUser.Photos.Add(new PhotoDBObject {
Line 58: BinaryData = photo.Data;
Source File: c:…ControllersProfileController.cs Line: 27
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] App.Controllers.ProfileController.NewListing() in c:...ControllersProfileController.cs:27 lambda_method(Closure , ControllerBase , Object[] ) +101 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +59 ... some lines skipped... System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +932 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +188
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34212
To fix this you need to initialise the collection first:
[HttpPost]
public ActionResult NewListing(ListingModel model) {
var newListing = new ListingDBObject {
Price = model.Price,
Title = model.Title,
ContactNumber = model.ContactNumber
}
newUser.Photos = new List<PhotoDBObject>(); // Initialise the collection first so it's not null
foreach (var photo in model.Photos) {
newUser.Photos.Add(new PhotoDBObject { // Add objects to the collection
BinaryData = photo.Data;
});
}
//...here goes code that saves new listing to the database
}
But Wait, There’s More!
I hope this article helped you to solve your problem and saved you a bit of time and frustration!
Don’t miss my next post — subscribe to the mailing list to get handy tips and solutions for ASP.NET
NVC Core. I never spam, and you can unsubscribe at any time.
Subscribe now and get helpful tips on developing .NET apps — never miss a new article.
The “Object reference not set to an instance of an object” error is a prevalent Windows error that originates from a Microsoft Visual Studio issue. This error code will appear in a situation where a Microsoft Visual Studio object is missing, is classified as null, or cannot be reached.
As it turns out, this issue is not specific to Microsoft Visual Studio developers as it can also be thrown by other applications that are built using Microsoft Visual Studio dependencies. Here’s a shortlist of potential culprits that are most likely responsible for this problem:
- Missing Windows 1803 Update on Windows 10 – If you’re still using Windows 10, chances are you’re experiencing this problem due to a conflict between some of your system drivers and some of the touchscreen devices that are currently installed (most commonly experienced with Surface devices). Microsoft has fixed this issue via the 1803 update, so install it if it’s missing from your computer.
- Corrupted Visual Studio data – If you’re experiencing this issue while attempting to use Microsoft Visual studio, the problem is most likely related to some kind of corruption affecting your current user data. To fix this problem, you’ll need to reset the user data currently associated with your account.
- Missing Microsoft Visual Studio permissions – Another scenario that will produce this error is a scenario in which the Microsoft Visual Studio application doesn’t have the required permissions to override files. To fix this issue, you’ll need to force the application to open with administrator access.
- A conflict caused by the ouch Keyboard and Handwriting Panel Service – If you’re actively using devices with a touchscreen surface or your device supports it natively, there’s also the possibility that the Touch Keyboard and Handwriting Panel Service is causing this problem. You can test out this theory by temporarily disabling this service.
- Updated Microsoft Visual Studio version – If you’ve just imported a new project into Microsoft Visual Studio and you started getting this error, it’s possible that the error is occurring because you’re using an outdated Visual Studio version that’s incompatible with the project you are trying to open. In this case, you can fix the issue by updating your MS Visual Studio version.
- Outdated Microsoft Visual Studio version – If you’re relying on one or more Visual Studio extensions in your projects, make sure all of them are updated. Several users have confirmed that they managed to fix this error by updating every used Visual Studio extension.
- Missing ASP.NET or Web Tools dependency – In case you only get this error while attempting to open projects that are using Web Tools and ASP.NET dependency, you should double-check and ensure that you actually have these dependencies installed.
- Vault Server Problem – If you get this error while attempting to access your AutoDesk Vault, you should first check the status of the critical Vault services and ensure that they’re up and running.
- Corrupted local Vault Client profile – As it turns out, this issue can also occur in a situation where the current Vault user profile that you’re actively using has become corrupted. In this case, you can fix the issue by deleting your local Vault User profile and starting from scratch.
- Outdated Vault version – In case you only see this error while attempting to access your AutoDesk Vault and you already ensured that the servers were not affected, you should start by making sure that you’re using the latest Vault deployment package locally. If you’re not updated to the latest version, perform the update manually.
- Corrupted Vault installation – Under certain circumstances, you might experience this problem due to a wider case of corruption that affects your local Vault installation. In this case, you can fix the problem by reinstalling the entire local Vault infrastructure.
- Antivirus or firewall interference – In some cases, you might experience this problem in a scenario in which your active antivirus ends up blocking the execution of another executable from the Vault ecosystem. In this case, you can resolve the issue by whitelisting the executable that gets flagged or by uninstalling the overprotective suite.
Now that we went over every potential reason why you might see the “Object reference not set to an instance of an object” error, let’s go over every confirmed fix
1. Install the 1803 Update (Windows 10 Only)
The error is sometimes received when loading the Juris® Suite Inquiry on Windows 10 Professional Edition computers. Upon investigating, found that this issue is caused by a Windows Update and has been resolved by a hotfix included in the Windows Update 1803.
Update: The error can also occur due to a conflict on some touchscreen devices, such as Microsoft Surface.
In case you’re experiencing this issue on Windows 10 and you haven’t installed the 1803 update yet, updating should take care of the issue if this is the root cause of the problem.
If you’re looking for specific instructions on how to update, follow the instructions below:
- To open the Run dialog box, press Windows key + R. In the text box, type “ms-settings:windowsupdate” and press Enter to go to the Windows Update tab in Settings.
Access the Windows Update component - In the Windows Update screen, go to the right section and click Check for Updates.
Check for Updates - After the initial scan is complete, install any pending Windows updates. If you have a lot of updates, you might have to restart before you can install all of them. If so, restart as instructed, but come back to this screen after startup to finish installing the updates.
- When you finish installing updates, reboot your computer one final time and see if the “Object reference not set to an instance of an object” error is still occurring.
If this fix was not applicable or it didn’t fix the issue in your case, move down to the next method below.
2. Disable the Touch Keyboard and Handwriting Panel Service (if applicable)
If you previously confirmed that the Windows Update 1803 is installed on your Windows 10 version, the next thing you should investigate is a potential conflict caused by the Handwriting Panel Service.
Several users that are dealing with the same issue have confirmed that they finally managed to take care of the “Object reference not set to an instance of an object” error after effectively disabling the Touch Keyboard and Handwriting Panel from the services screen.
Warning: This procedure will affect the usage of any connected touch screen device. Don’t attempt this fix below if you’re using a touchscreen device like Microsoft Surface since it will effectively break the touchscreen functionality.
If you are prepared to apply this fix, follow the instructions below:
- Press Windows key + R to open up a Run dialog box. Next, type ‘services.msc’ and press Ctrl + Shift + Enter to open up the Services screen with admin access.
Open up the services screen - At the User Account Control (UAC), click Yes to grant admin access.
- Once you’re inside the Services screen, scroll down through the list of available services and locate the Touch Keyboard and Handwriting Panel service.
- When you see it, right-click on it and choose Properties from the context menu.
Accessing the Properties screen - Once you’re inside the Properties screen of Touch Keyboard and Handwriting Panel service, access the General tab and set the Startup Type to Disabled before hitting Apply to save the changes.
- Restart your PC and check if the problem is now fixed by repeating the same action that was previously causing the “Object reference not set to an instance of an object” error.
If the problem is still not resolved, move down to the next method below.
3. Reset Visual Studio user data
User data may also be the root cause of the “Object reference not set to an instance of an object” error. To fix this, we need to reset all user data related to Visual Studio.
Note: Please note that your user settings, such as Visual Studio layout, linked Microsoft account, or start page, may be lost after you perform the procedure below.
To accomplish this, we’ll need to access the user Visual Studio folder (under AppData) via File Explorer and delete the contents inside before restarting Visual Studio.
Follow the instructions below for step-by-step instructions on how to do this:
- First things first, make sure that Visual Studio is closed and not running in the background.
- Open File Explorer and navigate to the following location:
C:Users%userprofile%AppDataLocalMicrosoftVisualStudio
Accessing the Visual Studio User Profile - Once you arrive inside the correct location, clear the contents of the folder by selecting everything, then right-clicking on a selected item and clicking on Delete.
- Restart your PC, then open Visual Studio once again and see if the problem is fixed.
In case this method was not applicable or it didn’t fix the issue in your case, move down to the next potential fix below.
4. Run Microsoft Visual Studio with the required Permissions
Another scenario that might end up producing this issue is a scenario in which Microsoft Studio doesn’t have the required permissions to edit files from the projects that you’re opening inside the program.
This is way more common on Windows 10 where the developing environment does not open with admin rights by default.
Fortunately, you can force Microsoft Visual Studio to open with the necessary permissions by forcing your OS to open it with admin access.
If you haven’t tried this yet, follow the instructions to open Microsoft Visual Studio with the required permissions:
- Start by pressing the Windows key, then type Visual Studio in the search bar at the top.
- From the list of results, right-click on Visual Studio and then click on Open file location from the context menu that just appeared.
Open the file location of Visual Studio - Next, right-click on Visual Studio from the revealed location, then click on Run as Administrator from the context menu.
- Now that you’ve ensured that Visual Studio opened with the necessary permissions, repeat the action that was causing the “Object reference not set to an instance of an object” error and see if the problem is fixed.
If the issue is still ongoing, try the next fix below.
5. Update Microsoft Visual Studio
Microsoft regularly releases updates for Visual Studio to address common bugs and errors. For example, the “Object reference not set to an instance of an object error” can be fixed with an update if the problem is related to an application bug. Thus, it is important to keep Visual Studio up-to-date to avoid this and any similar errors.
Despite the fact that Microsoft Visual Studio prompts users when a new update is available, one should check for updates manually from time to time, just in case the prompt was missed or ignored.
Follow the instructions below to check if a new update is available for your current Visual Studio version:
- Press the Windows key on your keyboard and type ‘Visual Studio Installer‘ inside the search box at the top.
- From the list of results, click on the Open button associated with Visual Studio Installer.
Opening the Visual Studio Installer - Once the Visual Studio Installer utility is opened, wait until the auto-check is performed. If a new version is identified, you will be prompted by an Update button.
- Click on the Update button, then follow the on-screen instructions to complete the installation of the available update.
- After the new version is installed, reboot your PC and see if the “Object reference not set to an instance of an object” error is fixed once the next startup is complete.
In case the same problem is still occurring or your Visual Studio version was already updated to the latest, move down to the next method below.
6. Update Microsoft Visual Studio Extensions
Even if you made sure that you’re running on the latest version of Microsoft Visual Studio, it’s still likely that some of the extensions (if you’re using any) might be outdated and indirectly cause the “Object reference not set to an instance of an object” error.
If you’re actually relying on Visual Studio extensions in your development, follow the instructions below to check if every extension is updated to the latest version:
- First things first, make sure that you open the project that you’re experiencing the issue with.
- Once the project is loaded, use the ribbon bar at the top to click on Extensions, then click on Manage Extensions from the context menu that just appeared.
Managing the extensions - Once you’re inside the extensions tab, check if any of the available Visual Studio extensions need updating. If new updates are available, click on Update all and confirm the process.
Update the available Visual Basic extensions - Once every available update is installed, restart the application and see if the “Object reference not set to an instance of an object” error is fixed.
If this method was not applicable in your particular scenario, move down to the next method below.
7. Install Microsoft ASP.NET and Web Tools
Microsoft ASP.NET and HTML/JavaScript are all tools that are used to create dynamic web pages and prevent errors, such as “Object reference not set..”. If you don’t have these dependencies installed, chances are installing them will fix the issue automatically.
Fortunately, Visual Studio makes it easy to install Microsoft ASP.NET and Web Tools.
Follow the instructions below to install the missing Microsoft ASP.NET and Web Tools:
- Start by opening Visual Studio and load up your existing project that’s causing the problem.
- Once the project is loaded, use the ribbon bar at the top to click on Tools > Get Tools and Features.
Accessing the Get Tools and Features - Once you’re inside the Get Tools and Features menu, check the box associated with ASP.NET and web development, then click on Install while downloading.
Installing the ASP.NET and web development dependency - Once this dependency is installed, restart the application and see if the problem is now fixed.
If the problem is still not fixed, move down to the next method below.
8. Check for a Vault critical server problem (if applicable)
If you’re experiencing this issue while attempting to use the Vault server infrastructure provided by AutoDesk, one of the most common causes is an issue with the critical services used by the Vault Servers infrastructure.
To investigate whether this is the cause of the issue, follow the instructions below to check if the following services are all running:
- Autodesk Data Management Job Dispatch.
- SQL Server (AUTODESKVAULT)*.
- SQL Server Agent (AUTODESKVAULT)*.
- Windows Process Activation Service.
- World Wide Publishing Services.
If any of the services mentioned above are not running, start them manually to fix the “Object reference not set to an instance of an object” error:
- Log in to Windows on the Vault server, then press Windows key + R to open up a Run dialog box.
- Inside the run prompt that just appeared, type ‘services.msc’ and press Ctrl + Shift + Enter to open the Services screen with admin access.
Open up the services screen - Once you’re inside the Services Management Console, check the status of the services below and ensure that every one of them is currently running:
Autodesk Data Management Job Dispatch. SQL Server (AUTODESKVAULT)*. SQL Server Agent (AUTODESKVAULT)*. Windows Process Activation Service. World Wide Publishing Services.
- If any of these services are not currently running, right-click on each of them individually and click on Restart.
- Once every service is restarted, repeat the action that was causing the error and see if it’s now fixed.
If the “Object reference not set to an instance of an object” error is still occurring, move down to the next method below.
9. Delete the Local Vault Client Profile (if applicable)
Another potential cause that might trigger the “Object reference not set to an instance of an object” error when using the Vault Servers is some type of corruption that is affecting the Vault user profile.
If this scenario is applicable and you haven’t attempted this fix yet, all you need to do is every Autodesk folder that holds user data.
IMPORTANT: You will only be able to do this when the main application is closed. So before proceeding with the deletion of the folders below, close the Autodesk app.
Here are the folders that need to be deleted in order to clear the data related to the Vault Client Profile:
- “%APPDATA%AutodeskVaultCommon”
- “%APPDATA%AutodeskProductstream 20xx”
- “%APPDATA%AutodeskVault Explorer 20xx”
- “%APPDATA%AutodeskAutoCAD 20xx Vault Addin”
- “%APPDATA%AutodeskAutodesk Vault Basic 20xx”
- “%APPDATA%AutodeskAutodesk Vault Workgroup 20xx”
- “%APPDATA%AutodeskAutodesk Vault Professional 20xx”
- “%APPDATA%AutodeskAutoloader”
- “%APPDATA%AutodeskReference Repair Utility”
- “%APPDATA%AutodeskInventor 20xx Vault Addin”
- “%APPDATA%AutodeskVaultManager”
Note: Deleting these folders won’t affect the functionality of the Autodesk app. These folders will be automatically regenerated the next time you open the app.
If this method is not applicable or it didn’t work for you, move down to the next method below.
10. Update Vault version (if applicable)
In the past, this issue started occurring for AutoDesk users in scenarios where their Vault products were running on a deprecated version.
To make sure that you’re using the latest version, visit the official Vault Download page and download & install the latest available build.
If the problem is still not fixed or not applicable, move down to the next method below.
11. Uninstall and Reinstall Vault (if applicable)
If you’re experiencing issues with your Vault software, you may need to repair, reinstall, or uninstall Vault Server, Vault Client, or the Vault integration for a CAD product (depending on the scenario that is applicable).
This scenario is applicable in scenarios where the Autodesk software is inconsistent and you suspect that the local installation contains some corrupted components that are causing issues with the Vault integration.
Note: This method is only applicable in scenarios where you are using Autodesk Vault (Server, Client, or CAD integration). If you’re not using Vault at all, skip this method altogether and move down to the final fix below.
Depending on where the corruption initiates from, one of the sub-guides below should help you fix the issue:
- Uninstall and reinstall the Vault Client
- Uninstall and reinstall the Vault Server
- Uninstall and reinstall the Vault Integration
Note: Our recommendation is to follow the sub-guides in the same order as presented below and see if any of them ends up fixing the “Object reference not set to an instance of an object” error.
Uninstall and Reinstall the Vault Client
There are three main causes that will ultimately signal a potential corruption issue with the Thick Vault Client from Autodesk:
- The edition you’re using is not consistent with your package (e.g. you’re using Vault Office when you should be using Vault Professional)
- The software is behaving inconsistently due to a false positive.
- Some program file components have become corrupted.
If any o the scenarios described above are applicable, follow the instructions below to uninstall and reinstall the Vault Client:
- Start by pressing the Windows key + R to open up a Run dialog box.
- Next, inside the Run prompt, type ‘appwiz.cpl’ and press Enter to open up the Programs and Features menu.
Open up the Programs and Features menu - Once you’re inside the Programs and Features menu, locate the entry associated with Vault Basic, Vault Workshop, or Vault Professional (Client), right-click on them, and choose Uninstall.
Uninstall the Autodesk vault - From the uninstallation screen that just appeared, click on Uninstall from the list of available options.
Starting the Autodesk Vault uninstallation process - Click Uninstall again, then follow the on-screen instructions to complete the uninstallation.
Confirm the uninstallation process - Once the uninstallation is complete, visit the installation directory of Autodesk Vault and remove any leftover files.
- Restart your client, then reinstall the software from scratch using the provided installation media (or download link).
Uninstall and reinstall the Vault Integration
Integrating your Vault-enabled applications ( AutoCAD, Inventor, Revit, etc) with a Vault server enables interaction without needing to switch programs. If the Thick Vault client detects qualifying products during its installation, it will automatically install integrations.
However, if the AutoDesk Vault software is behaving inconsistently and you suspect that some of the files belonging to the installation have become corrupted, you can attempt to fix the issue by attempting to uninstall the Vault integration/s.
To do this, you would need to use the Programs and Features menu to “Change” the installation of the Thick Vault client and get rid of the problematic integration.
Follow the instructions below for specific instructions on how to do this:
- To begin, press the Windows key + R to open a Run dialog box.
- Inside the Run prompt, type ‘appwiz.cpl’ and press Enter to open the Programs and Features menu.
Open up the Programs and Features menu - Once you’re inside the Programs and Features menu, find the entry associated with Vault Basic, Vault Workshop, or Vault Professional (Client), right-click on it, and choose Uninstall/Change.
- The uninstallation screen will appear; click on Add or Remove Features from the list of available options.
Add or remove Features inside the AutoDesk vault - Next, you will get a list of all the integrations that are currently installed. Cycle through the list and untick the integration that is causing the problem from the list.
Removing the problematic integrations - Once you’ve excluded the integrations that you want to remove, click on Update to make the changes reflect on the Vault app.
- Follow the remaining instructions to complete the process, then reboot your PC and see if the problem is now fixed after going through the steps of reinstalling the integration that you’ve just recently removed.
If the same kind of issue is still occurring, move down to the next sub-guide below.
Uninstall and reinstall the Vault Server
If you notice that the software started to behave inconsistently and you burned through the other potential fixes above, you should investigate whether the programs or the components owned by Vault are actually corrupted and causing the problem.
In this case, you should be able to fix the problem by uninstalling and reinstalling the vault server.
Follow the instructions below for specific instructions on how to do this:
- To begin, press the Windows key + R to open a Run dialog box.
- Then, type ‘appwiz.cpl’ into the prompt and press Enter to access the Programs and Features menu.
Open up the Programs and Features menu - In the Programs and Features menu, locate the entry for Vault Basic,or Workgroup or Professional (Server). Right-click on the entry and select Uninstall from the drop-down menu.
Uninstall the Autodesk Vault Professional Server - A new screen will appear with the option to click on Uninstall. Click on Uninstall again and follow the instructions to finish the uninstallation.
Uninstalling the Autodesk Vault server installation - After uninstallation is complete, go to the installation directory of the Autodesk Vault server and remove any leftover files.
- Finally, restart your client and reinstall the software from scratch using the provided installation media (or download link).
If this method didn’t fix the issue in your case, move down to the next potential fix below.
12. Prevent antivirus interference (if applicable)
If you’ve come this far without a resolution that worked in your case, you should know that certain security software can sometimes be over-aggressive with their protection and block the communications of legitimate software like AutoDesk Vault.
If you’re certain that you’re dealing with a false positive, the only thing you can do is take some steps to prevent your active antivirus from interfering with the AutoDesk Vault.
AV suites such as Comodo, Avast, McAffee are often cited as the main culprits for causing this type of behavior with AutoDesk vault.
However, there may be other programs that will cause the same type of behavior. If you think your AV software might be the problem, you should start by disabling real-time protection and see if that makes the difference.
To disable real-time protection in most security suites, including Avast, simply go to the taskbar menu.
If you’re using a 3rd party security suite that also has a firewall, however, simply disabling real-time protection will not be enough. In this case, you will need to uninstall the entire security suite and clear any remnant files that might still cause problems.
Here is a quick guide on how to uninstall a problematic 3rd party security suite and clear any leftover files:
- To open the Programs and Features menu, press Windows key + R to open up a Run dialog box.
- Next, type ‘appwiz.cpl’ and press Enter.
Open up the Programs and Features menu - Scroll through the list of installed applications in the Applications and Features menu to find the 3rd party security suite you wish to uninstall.
- Next, right-click on it and choose Uninstall from the context menu.
Uninstalling antivirus suite - Follow the on-screen instructions to finish uninstalling, then restart your computer to save the changes.
- To remove any leftover files from the uninstalled AV suite, follow these instructions to ensure that you’re not leaving behind any AV files that might cause the same behavior.
- Repeat the action that was causing the “Object reference not set to an instance of an object” error and see if the problem is now fixed.
When a user wants to view another user profile on user profile page this error will show up
ERROR
Server Error in '/' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 72: protected void OnDataBound(object sender, EventArgs e) Line 73: { Line 74: string userName = (FormView1follow.Row.Cells[0].FindControl("hfUserName") as HiddenField).Value; Line 75: string friendsUserName = (FormView1follow.Row.Cells[0].FindControl("hfFriendsUserName") as HiddenField).Value; Line 76: string followStatus = (FormView1follow.Row.Cells[0].FindControl("hfFollowStatus") as HiddenField).Value;
HTML
<div class="text-center"> <asp:FormView ID="FormView1follow" runat="server" OnDataBound="OnDataBound" Width="100%"> <ItemTemplate> <asp:HiddenField ID="hfUserName" runat="server" Value='<%# Eval("UserName") %>' /> <asp:HiddenField ID="hfFriendsUserName" runat="server" Value='<%# Eval("FriendUserName") %>' /> <asp:HiddenField ID="hfFollowStatus" runat="server" Value='<%# Eval("FollowStatus") %>' /> <asp:LinkButton ID="btnfollowFollow" runat="server" ToolTip="follow user" CssClass=" btn btn-twitter fa fa-user" Font-Bold="True" > <i class="" style="margin-right:2px" ></i> <asp:Label ID="lblFollow" runat="server" Text='<%# Eval("Status1") %>' /> </asp:LinkButton> <asp:LinkButton ID="Unbtnfollow" runat="server" ToolTip="follow user" CssClass=" btn btn-twitter fa fa-user-plus" Font-Bold="True"> <i class="" style="margin-right:2px" ></i> <asp:Label ID="lblUnFollow" runat="server" Text='<%# Eval("Status2") %>' /> </asp:LinkButton></ItemTemplate> </asp:FormView> </div>
CODE
protected void Page_Load(object sender, EventArgs e) { if (Session["UserName"] != null && Session["UserName"].ToString() != string.Empty) { string userName = Session["UserName"].ToString(); if (!this.IsPostBack) { FormView1follow.DataSource = GetData(userName); FormView1follow.DataBind(); } } } private DataTable GetData(string userName) { DataTable dt = new DataTable(); // DataTable dt = new DataTable(); // dt.Columns.AddRange(new DataColumn[3] { new DataColumn("category", typeof(string)), new DataColumn("A10", typeof(Int32)), new DataColumn("A20", typeof(Int32)) }); // dt.Rows.Add('A', 1, 2); // dt.Rows.Add('B', 5, 3); // dt.Rows.Add('C', 2, 1); // dt.Rows.Add('D', 8, 1); // dt.Rows.Add('E', 7, 5); // string name = "FF"; //var querycount = (from dd in dt.AsEnumerable() // where dd.Field<string>("category") == name // select dd).Count(); string constr = ConfigurationManager.ConnectionStrings["CONN"].ConnectionString; string query = "SELECT u.UserName,u.FriendUserName,u.FollowStatus,u.Status1,u.Status2 FROM USERFollow as u WHERE u.UserName = '" + userName + "' OR u.FriendUserName='" + userName + "'"; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(query, con)) { con.Open(); using (SqlDataAdapter sda = new SqlDataAdapter(cmd)) { sda.Fill(dt); } con.Close(); } } return dt; } protected void OnDataBound(object sender, EventArgs e) { string userName = (FormView1follow.Row.Cells[0].FindControl("hfUserName") as HiddenField).Value; string friendsUserName = (FormView1follow.Row.Cells[0].FindControl("hfFriendsUserName") as HiddenField).Value; string followStatus = (FormView1follow.Row.Cells[0].FindControl("hfFollowStatus") as HiddenField).Value; LinkButton btnFollow = (LinkButton)FormView1follow.Row.Cells[0].FindControl("btnfollowFollow"); LinkButton btnUnFollow = (LinkButton)FormView1follow.Row.Cells[0].FindControl("Unbtnfollow"); if ((userName.Trim() != friendsUserName.Trim()) && (followStatus.ToLower().Trim() == "true")) { btnFollow.Visible = true; btnUnFollow.Visible = false; } else if ((friendsUserName.Trim() != userName.Trim()) && (followStatus.ToLower().Trim() == "false")) { btnFollow.Visible = false; btnUnFollow.Visible = true; } }
Check your GetData() doesn’t return any record.
micah
on Apr 13, 2016 11:20 AM
on Apr 13, 2016 01:54 PM
the error is because if the user is not found in table USERFollow it will through error, but if the user is found in USERFollow table and is connected to friendusername it will work
So to solve this errror, it will go like this. If the UserName in USER ACCOUNT is found in USERFollow table and is connected to FriedUserNAME or USERNAME show button CONNECTED.
But If not show not connected
something like this
"SELECT u.UserName,u.FriendUserName,u.FollowStatus,u.Status1,u.Status2 ,up.UserName,up.Name FROM USERFollow as u, USERAccount as up WHERE up.UserName = '" + userName + "' OR u.FriendUserName='" + userName + "'";
but i dnt know how to finish it
Thats i am saying as per the user your GetData doesn’t return any record. So OnDataBound you will get Object reference not set to an instance of an object. So write the Page_Load code like below.
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { if (Session["UserName"] != null && Session["UserName"].ToString() != string.Empty) { string userName = Session["UserName"].ToString(); DataTable dt = GetData(userName); if (dt.Rows.Count > 0) { FormView1follow.DataSource = dt; FormView1follow.DataBind(); } } } }
If dt count > 0 then bind the form formview.
micah
on Apr 18, 2016 04:34 AM
Now the issus am having here now is , only FriendUserNames who are connected to UserNames are seeing the button CONNETED, but those who are in UserName who are connected to FriendUserName cant see the button CONNECTED.
Secondly
For those users who are in USER ACCOUNT TABLE but are not connected to those either in UserName or those in FriendUserName supposed to see button NOT CONNECTED
CODE I USED
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { if (Session["UserName"] != null && Session["UserName"].ToString() != string.Empty) { string userName = Session["UserName"].ToString(); DataTable dt = GetData(userName); if (dt.Rows.Count > 0) { FormView1follow.DataSource = dt; FormView1follow.DataBind(); } } } } private DataTable GetData(string userName) { DataTable dt = new DataTable(); string constr = ConfigurationManager.ConnectionStrings["CONN"].ConnectionString; string query = " SELECT u.Id,u.Name,u.ImageName,s.SendDate,s.Status,s.Status2,s.FollowStatus,s.UserName,s.FriendUserName,s.Status,s.BlockUserStatus,s.Count FROM User3 u, USERFollow s WHERE u.UserName = s.UserName AND s.FriendUserName=@UserName "; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(query, con)) { con.Open(); // cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", Request.QueryString["Id"].ToString()); // cmd.Parameters.AddWithValue("@FriendUserName", Session["UserName"].ToString()); cmd.Parameters.AddWithValue("@FriendUserName", Request.QueryString["Id"].ToString()); using (SqlDataAdapter sda = new SqlDataAdapter(cmd)) { sda.Fill(dt); } con.Close(); } } return dt; } protected void OnDataBound(object sender, EventArgs e) { string userName = (FormView1follow.Row.Cells[0].FindControl("hfUserName") as HiddenField).Value; string friendsUserName = (FormView1follow.Row.Cells[0].FindControl("hfFriendsUserName") as HiddenField).Value; string followStatus = (FormView1follow.Row.Cells[0].FindControl("hfFollowStatus") as HiddenField).Value; LinkButton btnFollow = (LinkButton)FormView1follow.Row.Cells[0].FindControl("btnfollowFollow"); LinkButton btnUnFollow = (LinkButton)FormView1follow.Row.Cells[0].FindControl("Unbtnfollow"); if ((userName.Trim() != friendsUserName.Trim()) && (followStatus.ToLower().Trim() == "true")) { btnFollow.Visible = true; btnUnFollow.Visible = false; } else if ((friendsUserName.Trim() != userName.Trim()) && (followStatus.ToLower().Trim() == "false")) { btnFollow.Visible = false; btnUnFollow.Visible = true; } }
You cannot ask multiple queries within a question. It is requested Mark Answer the replies when question is answered and ask a new question as a responsible member to help fellow programmers around the world.