none
exception 'System.Windows.Forms.AxHost.InvalidActiveXStateException' RRS feed

  • Question

  • Active = 'ax.Active' ha generato un'eccezione di tipo 'System.Windows.Forms.AxHost.InvalidActiveXStateException'

    Hi All.

    I'm working in VS2010-C#. In a windows form application I'm trying to add an ActiveX component programmatically. I'm starting a thread and in the thread main function I'm creating a form. In the Form.Load method I'm adding programmatically an array of 8 ActiveX components.

    axSyac1 =

     

    new HandleActiveXSyacmany(8);

     

    foreach

     

    foreach

    foreach

     

     

    (AxSMStreamer.AxDEHtmlStreamer ax in this.axSyac1.axDeHtmlStreamers)

    {

    ((System.ComponentModel.

     

    ISupportInitialize)(ax)).BeginInit();

    ax.OnConnect +=

     

    new System.EventHandler(axDEHtmlStreamer_OnConnect);

    ax.OnDisconnect +=

     

    new System.EventHandler(axDEHtmlStreamer_OnDisconnect);

    ax.OnError +=

     

    new AxSMStreamer.IDEHtmlStreamerEvents_OnErrorEventHandler(axDEHtmlStreamer_OnError);

     

     

    this.Controls.Add((AxSMStreamer.AxDEHtmlStreamer)ax);

    ((System.ComponentModel.

     

    ISupportInitialize)(ax)).EndInit();

    }

    The new succeeds because the activexType control, axSyac1 in my code before is null and then has all properties and methods but, With the debugger I can see before the Controls.Add method that the state of all the properties of ax is "generated an exception of type 'System.Windows.Forms.AxHost.InvalidActiveXStateException' ".

    The first time I start the thread which creates the form; in Form.Load the Controls.Add(ax) succeeds, and afterwards I can see all the properties correctly initialized (false, 0, .... according to the type.

    Then without exiting the program I close the form and stop the thread. On the VS IDE thread window I can see the thread disappear. I restart the thread, the form is created, Form.Load is called but running the statement Controls.Add(ax) on the first element of the array I get the exception

    'System.AccessViolationException' in System.Windows.Forms.dll

    and I am not able to catch the error. It is as Unhandled exception has occured in the application. If I click continue, the application will ignore this error and attempt to continue but it closes immediately.

    Can anybody help please, I would really appreciate it.

    Thanks very much

     

    marco

    Thursday, February 3, 2011 4:31 PM

Answers

All replies

  •  

    Could you please move those logic from Form.Load method to the click event of a button? will the exception occur again?


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by eryang Monday, February 14, 2011 8:55 AM
    Tuesday, February 8, 2011 5:59 AM
  • Hi,

    thanks for the answer. As a matter of fact, I tried that; I moved the code first in Form_Shown() and then in a button_click code. It didn't change.

    I don't know the reason but I figured out that if when I start the program (Form_load of the main form)

    I create the guilty form and instantiate the ActiveX in it, just the new

    I immediately after set  to null this dummy form

    Everything works okay. If you have any hint about why this happens, it would be nice for me to understand.

    Thanks for your attention

    marco


    marco furlan
    Monday, February 14, 2011 11:36 AM