I keep getting the following progress error when the Destructor is being run in a dialog window:
System.NullReferenceException: Object reference not set to an instance of an object.
This happens when the following command is being executed:
IF VALID-OBJECT(components) THEN
DO:
CAST(components, System.IDisposable):Dispose().
END.
When I message out the following:
THIS-OBJECT:components:Components:Count, the count is equal to 2, so something is definitely there to be disposed of.
I am using progress 10.2B.
When I comment out all the code in the Destructor the error no longer appears - so how can I dispose of the components without the progress error?
Thanks
Steve
Have you tried assigning the CAST() result to a variable and then doing varName:Dispose()?
Hello Tim,
Thanks for your suggesting, I had a go with the following:
ASSIGN lvComponent = CAST(components, System.IDisposable).
lvComponent:Dispose().
..but I still get the same error.
I have also tried setting the dialog disposeDialogOnClose = FALSE instead of TRUE, followed by parent window command dialogName:DestroyForm(). This appears to fix the problem by NOT calling the Destructor at all, but I think avoiding running the Destructor is wrong, as the dialog is Still a valid object.
I'm thinking that the issue isn't the lvComponent, it's something inside the class that's trying to delete something that doesn't exist. Is there a stack trace / protrace somewhere to points to what's actually throwing the error?
I don't see how assigning to a variable would help. The problem is not in the ABL. It is on the .NET side. I don't think I've seen this error from a destructor like this. You probably need to log a bug to figure it out.
Good idea Tim. You can use debug-alert to see it and/or look at the StackTrace in the .NET object if you catch it.
"I don't see how assigning to a variable would help. "
It confirms whether it's some weird corner case with the AVM or something else. That the problem persists means its something else.
Thanks again - I have also tried working with adapting the disposedHandler method in community.progress.com/.../1256, but I still get the same progress error.
I'll carry out further attempts with locating the StackTrace / ProTrace, see what more I can learn. I was also wanting to find a way to list the components that are trying to be disposed of, but I wasn't able to access these properties.
Hello Tim / Laura
I believe I've fixed the issue.
When I did a count of the number of components in the Destructor, using THIS-OBJECT:components:Components:Count, I got the value 2.
So when the components are set up,
THIS-OBJECT:components = NEW System.ComponentModel.Container().
I found that THIS-OBJECT:components was being referenced 2 times (to binding sources):
THIS-OBJECT:bsDestinationStorageLocation = NEW Progress.Data.BindingSource(THIS-OBJECT:components).
THIS-OBJECT:bsShippingUnit = NEW Progress.Data.BindingSource(THIS-OBJECT:components).
So in the Destructor:
MESSAGE "First Count " THIS-OBJECT:components:Components:Count SKIP
VIEW-AS ALERT-BOX.
The First Count was 2.
I then disposed of the 2 binding sources:
THIS-OBJECT:bsDestinationStorageLocation:Dispose().
THIS-OBJECT:bsShippingUnit:Dispose().
MESSAGE Second Count " THIS-OBJECT:components:Components:Count SKIP
VIEW-AS ALERT-BOX.
The Second Count was zero.
So the following command (which was generating the error, which is still in the code is no longer failing as there are no remaining components to dispose of:
CAST(components, System.IDisposable):Dispose().
Thanks for your earlier suggestions - but it looks like the disposal of the binding sources has fixed the problem.
Steve
Great. Though that does not explain why the error was happening in the first place. But as long as your happy, I'm happy!