InvalidActiveXStateException from AxVideoSoftIndexTab control

ล็อกแล้ว InvalidActiveXStateException from AxVideoSoftIndexTab control

  • 18 กรกฎาคม 2554 19:29
     
     

    We are upgrading our VB 6.0 project to VB.Net 2008.

    In the some place on the parent form new form variable is crfeated by following code:

    m_frmChild = New frmChild

    This code initiates Child form initialization. Among others this include execution of the

    Sub InitializeComponent() in the form designer VB code. In this code there is one statement: 

    Me.ClientSize = New System.Drawing.Size(630, 382)

    that trigers Child form Resize event. In the Resize event among others we have reference to Video Soft Index Tab control. Type of the control is AxVideoSoftIndexTab. The statemen that produces trhe error is:

    Call ActionTab_Resize(vsTabActions.CurrTab)

    In this statementhat we just try to pass CurrTab to another Resize subroutine.

    Could anybody help us out. Thank you.


    • แก้ไขโดย A M T 18 กรกฎาคม 2554 19:32 formatting
    •  

ตอบทั้งหมด

  • 19 กรกฎาคม 2554 6:02
    ผู้ดูแล
     
     

    Hello AMT,

    Thanks for your post.

    The public properties and methods of an ActiveX control can only be referenced after the ActiveX control has been instantiated and initialized completely; otherwise the AxHost.InvalidActiveXStateException exception is thrown. The AxHost.InvalidActiveXStateException exception class contains the name of the member that made the reference and the member type. Please ensure the ActiveX control you used has been instantiated and initialized.

    If you have any concerns, please feel free to follow up.

    Have a nice day.

    Best regards


    Liliane Teng [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.

  • 19 กรกฎาคม 2554 16:05
     
     

    Dear Liliane,  Thank you for your reply. In my original post I have mentioned that problematic ActiveX control is xVideoSoftIndexTab. I have traced code execution though InitializeComponent() Sub for this form and move the statement

    Me.ClientSize = New System.Drawing.Size(630, 382)

    that couses form Resize event to the very end of this Sub. I do not know what else should be done in order to "instamsiate and initialize" this ActiveX control.

    Here is the copy of exception thrown:


    System.Windows.Forms.AxHost.InvalidActiveXStateException was unhandled
      Message="Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown."
      Source="AxInterop.VsOcxLib"
      StackTrace:
           at AxVsOcxLib.AxVideoSoftIndexTab.get_CurrTab()
      InnerException:

    Could you please help me out.

    Thank you.


    AMT
  • 19 กรกฎาคม 2554 23:49
     
     

    I have additional information regarding this issue.

    I try another general properties of this ActiveX control (such as Visible, Or Left, or Enabled) and all of them work properly.

    Only State setting and getting prperties do not work.

    May be this will be helpful for the resolution?

    Thank you


    AMT
  • 21 กรกฎาคม 2554 4:01
    ผู้ดูแล
     
      มีโค้ด
     I do not know what else should be done in order to "instamsiate and initialize" this ActiveX

    Hi AMT,

    When you new the ActiveX control, please initialize it such like below code(an example):

     Dim ax As New AxESACTIVEXLib.AxESActiveX()
    
     DirectCast(Me.ax, System.ComponentModel.ISupportInitialize).BeginInit()
    
     Me.Controls.Add(ax)
    
     DirectCast(Me.ax, System.ComponentModel.ISupportInitialize).EndInit()
    

    Please have a try and let us know the situation on your side.

    More information:

    http://msdn.microsoft.com/en-us/library/system.componentmodel.isupportinitialize.begininit.aspx
    (ISupportInitialize.BeginInit Method)
    http://msdn.microsoft.com/en-us/library/system.componentmodel.isupportinitialize.endinit.aspx
    (ISupportInitialize.EndInit Method)

    If you have any concerns, please feel free to follow up.

    Have a nice day.

    Best regards


    Liliane Teng [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.

     

    • ทำเครื่องหมายเป็นคำตอบโดย Liliane TengModerator 27 กรกฎาคม 2554 15:36
    • ยกเลิกการทำเครื่องหมายเป็นคำตอบโดย A M T 2 สิงหาคม 2554 21:18
    • ทำเครื่องหมายเป็นคำตอบโดย A M T 2 สิงหาคม 2554 21:18
    • ยกเลิกการทำเครื่องหมายเป็นคำตอบโดย A M T 2 สิงหาคม 2554 21:18
    •  
  • 25 กรกฎาคม 2554 14:38
    ผู้ดูแล
     
     

    Hi AMT,

    What about this problem on your side now? If you need further assistance about this issue, please feel free to follow up.

    Have a nice day.

    Best regards


    Liliane Teng [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.

  • 27 กรกฎาคม 2554 15:38
    ผู้ดูแล
     
     

    Hi AMT,

    When you come back, if you need further assistance about this issue, please feel free to let us know. We will continue to work with this problem.

    Have a nice day.

    Best regards


    Liliane Teng [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.

  • 28 กรกฎาคม 2554 17:03
     
     

    Dear Liliane,

    Thank you so much for your replies and aswers.

    I have been out of the office for 3 days therefore I did not have a chance to see them.

    Let me place here all the code from the Designer .VB module of the form related to problematic control:

    Public WithEvents vsTabActivity As AxVsOcxLib.AxVideoSoftIndexTab

    Me.vsTabActivity = New AxVsOcxLib.AxVideoSoftIndexTab
    Me.vsTabActivity.SuspendLayout()
    CType(Me.vsTabActivity, System.ComponentModel.ISupportInitialize).BeginInit()
    vsTabActivity.OcxState = CType(resources.GetObject("vsTabActivity.OcxState"), System.Windows.Forms.AxHost.State)
    Me.vsTabActivity.Location = New System.Drawing.Point(0, 24)
    Me.vsTabActivity.TabIndex = 0
    Me.vsTabActivity.Name = "vsTabActivity"
    CType(Me.vsTabActivity, System.ComponentModel.ISupportInitialize).EndInit()
    Me.Controls.Add(vsTabActivity)
    Me.vsTabActivity.Controls.Add(vsElasticActivity)
    Me.vsTabActivity.ResumeLayout(False)

    Working with my colleague intensively on this form we come up to unusual solution. After this code is already executed and all controls are instantiated and initialized he happens to open locals window with all the properties for problematic control displayed. There we saw that CurrTab property is no longer gives us the error.

    This incident directed us to additional investigation to find specific property of that ActiveX control accessing which fixes the erroneous state of the control.

    After tedious work I did find that property: it was AccessibilityObject property!

    I have included following code into Form_Resize event procedure where error occured:

    Dim objErrorFixer As AccessibleObject

    objErrorFixer = vsTabActivity.AccessibilityObject
    objErrorFixer = Nothing

    I have also included reference to assembly 'Accessibility, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' that required for this object.

    Even though we have fixed the problem our own way I would kike to try your solution as well.

    Could you please look at the initialization code above, and tell me what I need to change to try your recommendation.

    The only real difference I see is DirectCast in place of CType you recommended.

    May be I am missing something.

    Thank you very much.

    AMT


    AMT



    • แก้ไขโดย A M T 28 กรกฎาคม 2554 17:04 clarification
    • แก้ไขโดย A M T 28 กรกฎาคม 2554 17:06 spelling
    • แก้ไขโดย A M T 28 กรกฎาคม 2554 17:07 spelling
    • แก้ไขโดย A M T 28 กรกฎาคม 2554 17:13 spelling
    • ทำเครื่องหมายเป็นคำตอบโดย Liliane TengModerator 29 กรกฎาคม 2554 6:29
    • ยกเลิกการทำเครื่องหมายเป็นคำตอบโดย A M T 2 สิงหาคม 2554 21:12
    •  
  • 29 กรกฎาคม 2554 6:28
    ผู้ดูแล
     
     

    Hi AMT,

    You could also use CType to implement. Your solution is also right. The difference between the two keywords is that CType succeeds as long as there is a valid conversion defined between the expression and the type and DirectCast requires that the run-time type of an object variable to be the same as the specified type that it's being cast to. Really the same, not just that one can be converted to the other.

    Use DirectCast if you're absolutely positively sure that an object is the specified type and the run-time type of the expression are the same.  If you're not sure but expect that the conversion will work, use CType. The run-time performance of DirectCast is better than that of CType. However, DirectCast throws an InvalidCastException error if the argument types do not match, so you must be sure.

    More information, you could also check this article:

    http://www.codeproject.com/KB/vb/DirectcastVsCtype.aspx

    Glad to see you have fixed the problem. Have a nice day.

    Best regards


    Liliane Teng [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.

  • 29 กรกฎาคม 2554 22:38
     
     

    Dear Liliane,

    My understanding of your reply is that ActiveX control initialization code, generated by VB.Net converter from VB 6.0 project that I have displayed in my last reply is CORRECT.

    Despite that state properties of that ActiveX control can not be accessed.

    May be there is some problem with that ActiveX control.

    How accessing some property can fix the problem?

    Could you please comment on that?

    Thank you.


    AMT
  • 2 สิงหาคม 2554 8:31
    ผู้ดูแล
     
     

    Hi AMT,

    I could not see any problems on initializing ActiveX control on above code you provided. About how to access the properties of the ActiveX control, there is a step-by-step lesson on how to use ActiveX and Variant in VB.NET. Please check, hope it could make you get some ideas.

    http://www.ultimaserial.com/vbnettutor.html (How to use ActiveX and Variant in VB.NET)

    If you have any concerns, please feel free to follow up.

    Have a nice day.

    Best regards


    Liliane Teng [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.

  • 11 สิงหาคม 2554 4:07
    ผู้ดูแล
     
     

    Hi AMT,

    Do you have any updates on this issue?

    Have a nice day.

    Best regards


    Liliane Teng [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.