Why(!): Object reference not set to an instance of an object error
The error "Object reference not set to an instance of an object" is quite uninformative leading to frustrating searches for solutions. In this document we'll take a look at the most common reasons for the error.
Searching for the error on SCN (search box is in top right corner), I come up with no less that 15 KBAs related to Crystal Reports and Visual Studio .NET. In this Document I do a quick summary / grouping of possible reasons for the error. The 15 KBAs resolve to 6 common groups; from bad coding, to database issues to report design and so on.
Mistakes leading to the error - General
The following are common non Crystal Reports related factors leading to the error:
- Not declaring variables.
- Use the appropriate scope.
- Bad inits/constructs.
- "buried" controls.
For more information see the thread Common causes of: Object reference not set to an instance of an object error.
Mistakes leading to the error - Specific to Crystal Reports
- Service Packs or updates not applied. A quick search for the error (crystal net Object reference) returns no less than four KBAs specifying the error and resolution being an update for the product. If you are interested, the following KBAs fall into this category; 2022806, 1525822, 1336586, 1544675.
- Incorrect runtime deployed, no runtime deployed, incorrect assemblies referenced in the project. Not all versions of Crystal Reports are supported in all versions of Visual Studio .NET. For details see the wiki Which Crystal Reports assembly versions are supported in which versions of Visual Studio .NET. For your reference the following KBAs apply; 1566763, 1836369, 1474515.
- Incorrect report design. The error may be thrown if a report object is placed outside the report design pane. Reference KBA 1865556. Other design issues may also cause the error.
- Incorrect code, incorrect standards. See KBA 1493619, 1569982, 1664415, 1626917.
- Database connectivity issues. Reference KBA 1494929.
- Incorrect or invalid use of controls. See KBA 1544651.
Note that the above is not meant to be an exhaustive treatment of all issues leading to the error. No doubt, there are more. And as we discover new reasons for the error, these are documented in our KBA system. New KBAs and other knowledge is tweeted on a daily bases and I invite you to follow us on Twitter:
Other twitter accounts worth following may be: