The error message indicates that you are modifying a collection inside a For Each loop that enumerates it, which is not allowed. If you're getting this error when you run your app then it indicates that you haven't tested it properly because that sort of thing you be found while testing/debugging.
Does this have something to do with how we close forms? We closed some of the forms in our application using the .Dispose method.
That shouldn't really matter, although you shouldn't really be calling Dispose on a form to close it. You should either be calling Close or else setting the DialogResult if it was displayed with ShowDialog. The only time you should be calling Dispose explicitly is when you're done with a modal dialogue but, even then, you should be disposing implicitly with a Using block, so an explicit Dispose call shouldn't ever be necessary.
Like I said though, it shouldn't matter in this context. The problem is exactly as I said: you're almost certainly modifying a collection within a For Each loop.
Modifying a collection within a For Each loop? But, as far as I know, I didn't even use a for each loop in my application. How is this possible?
Hmmm... let me use my vast knowledge of your application to answer that. Seriously though, that's why you catch exceptions and debug code. Maybe there's something dodgy going on behind the scenes and its not your loop or collection. If you either examine the exception in the debugger or catch the exception and examine it at run time to see exactly where it occurs. Try handling the UnhandledException event of the application and examining the exception, particularly the stack trace.
That's rather weird. I know I have placed Try-Catch statements on all the events that I've used, except for the form_closing ones. Should I try using a general exception handler or is there a specific exception handler used for this kind of situation?
Without knowing more about your application, i.e. the code that you are using, it is going to be difficult to help you much more.
Have you tried stepping through your code in the debugger, using breakpoints. At some point, an exception is getting thrown in your code that you are not handling. What course of actions do you take in your application to make it happen? Do you click a button? If so, set a breakpoint in the code, at this point, and then start stepping through the code.
This only happens when we run the application after it has been deployed (installed). It's running just fine when we run it using VS, that's why I don't know which code to place here.
Ok, so perhaps some information about what your application does?
Have you deployed all necessary 3rd party dll's that your application needs? Are there any specific Application Settings that need to be changed, i.e. where a file is located, the installation path. Have you got any hard coded references to files in your application, that aren't there on the deployed system?
There has to be something different between the two installations.
A good idea would be to add logging to your application, that way you can see exactly what your code is doing when it throws the exception.