Reporting Services Migration Error: Object reference not set to an instance of an object.
In working with a customer doing a migration from Reporting Services 2005 to 2008 an error appeared when in preview mode that didn’t appear in the previous version. The error was simply #Error in the report and the Error pane in Visual Studio showed The Value expression for the field ‘<my field name>’ contains an error: Object reference not set to an instance of an object. We have all seen the ‘object reference not set’ at one point in our lives. After doing some trouble shooting it turns out that the report was calling out to an external assembly to do some work building a data table and then getting the summary values for the data table in another call. The data table was originally built using a hidden table in the report and the values were accessed in a field in another report table. Because of the positioning of the tables the hidden table would execute first, therefore creating the data table in code, and the expression to get the values would execute afterwards.
This reliance of execution order was the root cause of the problem. In SSRS 2008 the execution order has changed. Refer to Robert Bruckner’s blog for more information. For this particular report the data table was not created first which caused the row collecting summary data from the expected table to be null. This in turn caused the value being retrieved to be null. Although the code checked for (x == DbNull.Value) it didn’t explicitly check for (x == null), so a cast later on in the code block created the ‘object reference not set to an instance of an object’ error.
What can cause confusion is the error itself, which says that Value expression for the field <y> contains an error. I racked my brain trying to figure out why that particular field was causing the error. It wasn’t. The logic, to my best guess, just parses the last parameter calling out to the external assembly that is a field in the report. I took my field that was stated to be the issue and changed it to an empty string. The next run of the report showed that the next parameter was the issue, and the next and the next until I had eliminated all of them.
The important thing to remember here is that relying on execution order in a report may cause issues when migrating to SSRS 2008. Try to avoid it if at all possible.
Comments
- Anonymous
March 27, 2009
PingBack from http://blog.a-foton.ru/index.php/2009/03/27/reporting-services-migration-error-object-reference-not-set-to-an-instance-of-an-object/