I am writing a control in C# that requires me to use an ActiveX control created in VB6. It works fine running from inside the IDE in both debug and release mode.
However, when I try to run an installed version, I get an InvalidActiveXStateException whenever I try to access a method or property of the ActiveX control. For instance, there is a connection property that is defined in the ActiveX control as:
Public Function Connect(Hostname As String, Port As Long, _
Flags As Integer, UserName As String, _
Password As String) As Integer
Inside the C# code, I call it like this:
Result = axMyControl.Connect(ref m_HostName,
ref m_Port, ref Flags, ref m_UserName, ref m_Password);
catch (Exception e)
MessageBox.Show("Unable to connect to " + m_HostName +
"\n" + e.Message, "Connection Error",
The exception is always thrown here (and anywhere else I try to access the code).