Problems disposing of form
I have a button on form1 which opens form2.
The functionality of form2 is reliant upon some of Office being installed. Basicall the Document Imaguing tools of Office.
If these are not present then the InitializeComponent() method of the forms constructor throws an exception :
Code:
[System.Runtime.InteropServices.COMException] = {"Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"}
I can obviously trap this with a try catch in the constructor but the problem is I cannot dispose of the problem.
How can I shut this "form2" down and clean up ?
The Initialise() hasd not completed so I have this half arsed mess.
Thanks In Advance
Re: Problems disposing of form
Can you avoid using the Office functionality in the constructor and defer it to the Load event handler?
Re: Problems disposing of form
Unfortunatly not. It's required at design time in VS.
This sucks big time.:mad:
Re: Problems disposing of form
Is it reasonable for the user to use your app at all if this functionality is not available? If not then you could attempt to create an object in code in the app's Startup event handler and refuse to continue if it fails.
Re: Problems disposing of form
The functionality offered by this form is not required by 90% of users so this problem rarely comes up.
Re: Problems disposing of form
How about testing the availability of the Office Document Imaging Tools in the Load event of your initial form and disabling the button if it is not found?
Re: Problems disposing of form
To be honest Hamish I'm not sure how to do that though it does sound like a reasonable solution.
Any tips ?
Re: Problems disposing of form
What piece of code throws the error in the constructor of Form2?
Isn't it possible to try that (just for testing) in the Load event of your initial form, and if it throws the same error you disable the button?
Re: Problems disposing of form
I agree. If you know that an insurmountable problem could arise in a few moments, check to see whether the problem happens before you get backed into a corner. Do whatever you need to do to confirm that the proper components exist, and don't even let the code go to the bad place if the component isn't available.
Re: Problems disposing of form
in form1 at button_click events
use try catch method to look the avaiable office components.
and give message to the user if the system is under req's and skip the form2.show statement.