Hi all!
I have an application that use Reflection to load some addins.
If I try Application.Restart() or Application.Exit() the result is an error:
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext()
at System.Windows.Forms.Application.ExitInternal()
at System.Windows.Forms.Application.Restart()
at frmMain.btnButton1_Click(Object sender, EventArgs e) in xxxxxxx
In OnFormClosing event i do this:
1. private
void frmMain_FormClosing(object sender, FormClosingEventArgs e)2. {
3. if (e.CloseReason == CloseReason.UserClosing)
4. {
5. this.Hide();
6. e.Cancel = true;
7. }
8. else
9. {
10. bool CanDispose = _pluginManager.RequireDispose();
11. if (CanDispose) _pluginManager.DisposePlugins();
12. e.Cancel = !CanDispose;
13. }
14. }
Where in lines 10-12 PluginManager asks all addins if they can be disposed immediately. If I comment lines 10-12 all works fine.
Please, does anybody know how to fix this