ProblemUser launches Controller client via a web client (URL). User receives error message. Show
SymptomSystem.NullReferenceException: Object reference not set to an instance of an object. CauseThere are several different possible causes for the same error message.
This IBM Technote shall specifically concentrate on the scenario where the administrator has forgotten to edit the file "applicationHost.config". This means that (by default) downloading .config files is blocked by the IIS webserver.
EnvironmentApplication server based on Windows 2008. Resolving The ProblemModify the file "applicationHost.config" so that the relevant entry now reads: <add fileExtension=".config" allowed="true" /> Steps:
In other words, modify the line to read: <add fileExtension=".config" allowed="true" /> TIP: for more information on the above, see separate IBM Technote #1449854. Related Information[{"Product":{"code":"SS9S6B","label":"IBM Cognos Controller"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Controller","Platform":[{"code":"PF033","label":"Windows"}],"Version":"8.5.1;8.5;10.1;10.1.1","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}] Object reference not set to an instance of an object error is one of the most common errors when developing .NET applications. Here are five most common mistakes that result in this error. In this article, also learn how to fix error, object reference not set to an instance of an object. Why does this error happen? This error's description speaks for itself but when you do not have much experience in development, it is very difficult to understand. So, this error description says that an object that is being called to get or set its value has no reference. This means that you are trying to access an object that was not instantiated. Why should I know this? This is important in order to avoid runtime errors that could possibly expose your sensitive data and this could lead to a vulnerability breach. Vulnerability breaches are usually used by hackers for a cyber attack to steal your data or to take your server offline. How to avoid exposing code and entities?You must always wrap code that could possibly throw an exception inside try-catch blocks. There are others security approaches that you can use to protect your data that can be found here. Common mistakes Objects used in this sample. Controller
Classes
New object not instantiated Practical example, Here, we have a sample situation of when we have this error.
This happens when you create a new object but do not instantiate it before getting/setting a value. Condition statement(if, switch)Practical example Here, we have a sample situation of when we have this error,
Why does this happen? This is a very common mistake. It happens when you create an object that is going to be instantiated inside a conditional statement but forgets to instantiate it in one of the conditions and try to read/write on it. Object Inside ObjectPractical Example Here, we have a sample situation of when we have this error:
Why this happens? It happens when you have an object with many child objects. So, you instantiate the main object but forget to instantiate its child before trying to get/set its value. Add item in a null listPractical Example Here we have a sample situation of when we have this error,
Why does this happen? When you are trying to read/write data in a list that was not instantiated before. Important
Best practices
*I am planning to write more about common mistakes and to share tips to improve code quality. If you have any specific topic that you would like to read here, please write it below in the comments section. Congratulations! You just learned how to deal with the most common daily mistakes. Download the code from GitHub here. How do I fix object reference is not set to an instance of an object?To fix "Object reference not set to an instance of an object," you should try running Microsoft Visual Studio as an administrator. You can also try resetting the user data associated with your account or updating Microsoft Visual Studio to the latest version.
What is NullReferenceException object reference not set to an instance of an object?The message "Object not set to an instance of Object" means you are trying to use an object which has not been initialized. This boils down to one of these: Your code declared an object variable, but it did not initialize it (create an instance or 'instantiate' it)
How do I fix NullReferenceException in C#?You can eliminate the exception by declaring the number of elements in the array before initializing it, as the following example does. For more information on declaring and initializing arrays, see Arrays and Arrays. You get a null return value from a method, and then call a method on the returned type.
Why am I getting a NullReferenceException?This error is caused when an object is trying to be used by a script but does not refer to an instance of an object. To fix this example we can acquire a reference to an instance of the script using GameObject.
|