|
-
Jan 14th, 2009, 08:48 AM
#1
Thread Starter
Fanatic Member
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
-
Jan 14th, 2009, 08:58 AM
#2
Re: Problems disposing of form
Can you avoid using the Office functionality in the constructor and defer it to the Load event handler?
-
Jan 14th, 2009, 09:08 AM
#3
Thread Starter
Fanatic Member
Re: Problems disposing of form
Unfortunatly not. It's required at design time in VS.
This sucks big time.
-
Jan 14th, 2009, 09:10 AM
#4
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.
-
Jan 14th, 2009, 09:15 AM
#5
Thread Starter
Fanatic Member
Re: Problems disposing of form
The functionality offered by this form is not required by 90% of users so this problem rarely comes up.
-
Jan 14th, 2009, 09:37 AM
#6
Hyperactive Member
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?
-
Jan 14th, 2009, 09:43 AM
#7
Thread Starter
Fanatic Member
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 ?
-
Jan 14th, 2009, 01:22 PM
#8
Hyperactive Member
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?
-
Jan 14th, 2009, 09:40 PM
#9
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.
My usual boring signature: Nothing
 
-
Feb 5th, 2009, 10:10 PM
#10
Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|