I got this exception  . How to solve this ?   Exception :Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown.

Teenu R
Teenu R used Ask the Experts™
on
I have a windows form  and two ocx controls are  added in this form. At runtime i got this exception.I think the exception is occurred when initialize the occ controls. i attached my code below. please help me . its very urgent.


using AxVSpinAccess2Lib;
using AxVSpinLib;
namespace VspinCentrifugeIntegration
{
    partial class frmInstrument
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            try
            {

                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
            catch
            {
            }

        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
           
                System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmInstrument));
                this.axVSpin1 = new AxVSpinLib.AxVSpin();
               // axVSpin1.CreateControl();
                this.axVSpinAccess21 = new AxVSpinAccess2Lib.AxVSpinAccess2();
                this.performanceCounter1 = new System.Diagnostics.PerformanceCounter();
                ((System.ComponentModel.ISupportInitialize)(this.axVSpin1)).BeginInit();
                ((System.ComponentModel.ISupportInitialize)(this.axVSpinAccess21)).BeginInit();
                ((System.ComponentModel.ISupportInitialize)(this.performanceCounter1)).BeginInit();
                this.SuspendLayout();
               
                //
                // axVSpin1
                //
                this.axVSpin1.CausesValidation = false;
                this.axVSpin1.Enabled = true;
                this.axVSpin1.Location = new System.Drawing.Point(46, 23);
                this.axVSpin1.Name = "axVSpin1";
                this.axVSpin1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axVSpin1.OcxState")));
                this.axVSpin1.Size = new System.Drawing.Size(100, 50);
                this.axVSpin1.TabIndex = 0;
                this.axVSpin1.Visible = false;
                //
                // axVSpinAccess21
                //
                this.axVSpinAccess21.CausesValidation = false;
                this.axVSpinAccess21.Enabled = true;
                this.axVSpinAccess21.Location = new System.Drawing.Point(64, 89);
                this.axVSpinAccess21.Name = "axVSpinAccess21";
                this.axVSpinAccess21.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axVSpinAccess21.OcxState")));
                this.axVSpinAccess21.Size = new System.Drawing.Size(100, 50);
                this.axVSpinAccess21.TabIndex = 1;
                this.axVSpinAccess21.Visible = false;
                //
                // frmInstrument
                //
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(231, 151);
                this.Controls.Add(this.axVSpinAccess21);
                this.Controls.Add(this.axVSpin1);
                this.Name = "frmInstrument";
                this.Text = "frmInstrument";
                ((System.ComponentModel.ISupportInitialize)(this.axVSpin1)).EndInit();
                ((System.ComponentModel.ISupportInitialize)(this.axVSpinAccess21)).EndInit();
                ((System.ComponentModel.ISupportInitialize)(this.performanceCounter1)).EndInit();
                this.ResumeLayout(false);
           

        }

        #endregion

        private AxVSpin axVSpin1;
        private AxVSpinAccess2 axVSpinAccess21;
        private System.Diagnostics.PerformanceCounter performanceCounter1;
    }
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Freelance programmer / Consultant
Commented:
       /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
           
                System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmInstrument));
                this.axVSpin1 = new AxVSpinLib.AxVSpin();
              // axVSpin1.CreateControl();


Have you modified the file yourself?  Also see the comment supplied by system.
Top Expert 2016
Commented:
there are no google results neither for AxVSpinAccess2Lib, nor AxVSpinLib, nor AxVSpin. so it must be a private class.

can you post the source code for this class?

from exception it seems that the class is managed by class AxHost. if you google for InvalidActiveXStateException you will find solutions which tell that you need o call method CreateControl in order to get the active x control into a correct state. so the question is why you commented the call to CreateControl (see also comment of Andy)?

Sara
AndyAinscowFreelance programmer / Consultant

Commented:
Probably modifying the file (despite warnings not to) is causing the problem.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial