locked
Exception of type 'System.ExecutionEngineException' was thrown. RRS feed

  • Question

  • I have a Windows Forms app that is using some WPF forms.  If I create an instance of my WPF form and show it using the following:

            private void ChangePassword()  
            {  
                ChangePasswordForm frm = new ChangePasswordForm();  
                UIHelper.InitializeWpfFormInterop(frm);  
                BillingUser usr = new BillingUser();  
                bool changed = false;  
                while (!changed)  
                {  
                    try 
                    {  
                        frm.NewPassword = "";  
                        frm.ShowDialog();  
                        if (frm.DialogResult.HasValue && frm.DialogResult.Value)  
                        {  
                            usr.ChangePassword(frm.CurrentPassword, frm.NewPassword);  
                            changed = true;  
                        }  
                        else 
                        {  
                            break;  
                        }  
                    }  
                    catch (Exception ex)  
                    {  
                        MessageBox.Show(ex.Message, "Change Password", MessageBoxButtons.OK);  
                    }  
                }  
                if (changed)  
                {  
                    MessageBox.Show("Your password was successfully changed.""Change Password", MessageBoxButtons.OK);  
                }  
            }  
         

            public static void InitializeWpfFormInterop(Window w)  
            {  
                System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(w);  
            }  
     

    That works great the first time.  But the next time I call ChangePassword(), I get...

    Exception of type 'System.ExecutionEngineException' was thrown.

    When InitializeComponent() is called during the call to new ChangePasswordForm();.  I think maybe it has something to do with what's going on in EnableModelessKeyboardInterop() but I just don't know enough about what's going on there to know what to do about it.  Is there something I should be doing at the end of ChangePassword to clean up the interop?

    Thanks!

    Ian
    Friday, January 2, 2009 9:47 PM

Answers

  • I tried your code in a simple WinFroms app with a Button click event handler to show a WPF Window as dialog, but does not repro the issue. It works fine. Do you have a callstack?
    • Marked as answer by Tao Liang Tuesday, January 6, 2009 7:13 AM
    Friday, January 2, 2009 10:21 PM

All replies

  • I tried your code in a simple WinFroms app with a Button click event handler to show a WPF Window as dialog, but does not repro the issue. It works fine. Do you have a callstack?
    • Marked as answer by Tao Liang Tuesday, January 6, 2009 7:13 AM
    Friday, January 2, 2009 10:21 PM
  • Did you find a solution to this?  I have a mixed application with WinForms and WPF forms, and I am getting the exact same error on the second time that I launch the form on InitializeComponenet
    Friday, January 29, 2010 3:45 PM
  • Changed the Application  ShutdownMode="OnExplicitShutdown".  This worked for me.
    Friday, January 29, 2010 4:00 PM
  • I am also facing the same problem. does anybody find the solution to this problem?  In my case there is no call stack, just a message "Exception of type 'System.ExecutionEngineException' was thrown."

     

    1. Mainform is windows form.

    2. wpf control with some buttons hosted on the form.

    3. clicking on the button opens wpf model window.

    4. close and reopen the wpf model window throws exception in InitializeComponent().

     

    Thanks.

     

    Wednesday, June 23, 2010 4:29 AM
  • @Thanks mapetrescu.. This worked for me also..

    The problem was after closing the window I was opening a new window, the contrsuctor of this new window was throwing the exception. So as you suggested, in the main method, before calling Application class object's Run method, I set its property ShutdownMode=ShutdownMode.OnExplicitShutdown;

    But if we add this property, we need to call System.Windows.Application.Current.Shutdown() while closing the last window(WPF window in my case). Otherwise application will be still running.

    • Edited by Sanjay Benni Friday, January 17, 2014 11:56 AM Added extra notes
    Friday, January 17, 2014 11:41 AM