Sunday, February 11, 2007

Crystal Reports Madness (Setter Exception)

Ran accross this fun little issue with a report that sets a Group condition...

We had some code like this:

Group group = report.DataDefinition.Groups[4];
group.GroupOptions.Condition = condition;

We used this to set a DateTimeCondition property of one of our reports. But everytime it hit this code an exception was thrown :(.

After spending a fair amount of time trying to track down a solution to this problem we found it to be an issue with the Setter for this object.

We changed our code to this and all is well again.

Group group = report.DataDefinition.Groups[4];
try {
group.GroupOptions.Condition = condition;
catch { }
group.GroupOptions.Condition = condition;

Basically we let it exception once, and don't handle it, and then set the property again. For some reason it always exceptions on the first attempt, but then sets the property fine the second time.

We found this solution by changing this value at runtime using the VS debugger. It would change the value fine at runtime if we modified the value in the watch window, but if we let it just try and pass through without manually changing the value then it would exception. If we manually changed the value and then stepped over the code, then it would work??

This is a strange one.

No comments: