System.InvalidOperationException

kkprakashmsc

Member
Joined
Jan 2, 2009
Messages
8
Programming Experience
1-3
Hi,
On click of menu a form should open. While opening the form, gives System.InvalidOperationException - An error occurred creating the form.
This error appears only on the production environment.. How to solve this?

please help me..
 
There's no way we can tell what is actually wrong but we can speak in general terms. When the error message says:
An error occurred creating the form.
it means that an exception was thrown during the execution of the InitializeComponent method, which is called from the constructor (Public Sub New) and is where your controls are created and configured in accordance with your actions in the designer. This InitializeComponent method contains code that sets properties and calls methods, just like any other. A fact that many people forget is that executing this code can cause events to be raised.

If you are handling these events and are expecting them to be raised only when the user has entered some data into your controls then you may be making invalid assumptions. For instance, maybe you're using the SelectedItem of a ComboBox that hasn't yet been populated. I'm not saying that that's what you're doing but it's an example of the sort of thing that can happen.

Now, no VB application should EVER crash. Even if an unexpected exception is thrown you should have handled the UnhandledException event of the application. There you can log the exception, notify the user that an unexpected error has occurred and exit gracefully. Not ideal but better than crashing. If you've done that then you can view your log and read the stack trace for the exception. It will tell you exactly where the exception was thrown. It will isolate it to the method at least and, if you distribute the PDB file with your EXE or DLL then it will give you the line number too.
 
Back
Top