The hell dreaded vb.net system.windows.forms.axhost+invalidactivexstateexception error is probably the plague of many converting old VB6 applications to VB.NET, especially if, like me, you’re new to working with either.
Finally, finally, I stumbled upon a forum snippet on www.CodeProject.com, page http://www.codeproject.com/Questions/55699/AxHost-InvalidActiveXStateException, and the guy’s problem wasn’t even mine, and wasn’t even fixed, but one lil ole line of code he had fixed my issue, at least a few of them.
Add controlname.CreateControl() in your form’s designer page, before the rest of its properties are set.
In my forms it was Me.controlname.CreateControl().
For whatever reason, Visual Studio 2008 saw fit to not include this in its code conversion.
Almost got sucked into other forum opinions that you need special Active X licenses to get such legacy controls to work in .NET.
UPDATE: My suggestion above isn’t for every such situation. On some forms I found that it was not a factor at all. Rather it was the way .Net forms are loaded from the form calling on them.
I had to switch the positioning of the first code accessing the values of any Active X elements to be after the ‘Show’ and/or ‘Activate’ commands for the form in which those elements reside.
Apparently, VB6 wasn’t so concerned about certain things that VB .Net obsesses over.
Hi,
I am using Windows Forms (not WPF) to create video controls on the form to view the output from a video stream. What I want to do is based on a list of IP addresses (the addresses being of encoders capturing the video and making it available via a URL), create a viewing control for each item. This is all being done using a 3rd party library.
I have no problem creating multiple objectes with the supplied DLL and setting the standard control properties. However, when I try to set any of the control custom properties I get:
An unhandled exception of type ‘System.Windows.Forms.AxHost.InvalidActiveXStateException’
This is all happening in the Form’s constructor. The code is:
public Form1()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
InitializeComponent();
AMC2.Enabled = false;
AMC2.Visible = false;
AxAXISMEDIACONTROLLib.AxAxisMediaControl AMC3 = new AxAxisMediaControl();
AMC3.Enabled = true;
AMC3.Location = new Point(126, 580);
AMC3.Name = "NewName";
AMC3.Size = new Size(720, 560);
Controls.Add(AMC3);
AMC3.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("AMC3.OcxState")));
AMC3.MediaUsername = "root"; //ERROR IS THROWN HERE
AMC3.MediaPassword = "pass";
AMC3.MediaURL = "axrtsphttp://99.999.999.99/axis-media/media.amp";
AMC3.MediaType = "h264";
AMC3.Play();
}
Can anyone tell me where I am going wrong here?
Thanks in advance for any help.
Hi,
I am using FirePass Client API to logon and access favorites for a user. (similar to sample given along with SDK)
However I get «Exception of type System.Windows.Forms.AxHost+InvalidActiveXStateException was thrown». I am not sure how to resolve this issue. Below is the console app I wrote. What am I missing?.. how do I properly initialize the ActiveX object and access Firepass?
Appreciate any help!
Thanks.
namespace testFirepass
{
class Program
{
///
/// Application Tunnels ActiveX control
///
private static AxAPPCTRLLib.AxAppTunnelEx axAppTunnel;
///
/// Favorite array instance (see OnGetFavorites)
///
private static APPCTRLLib.UPropertyArray Favorites = null;
public Program()
{
axAppTunnel.OnOpenSession += new AxAPPCTRLLib._IAppTunnelEventsEx_OnOpenSessionEventHandler(axAppTunnel_OnOpenSession);
axAppTunnel.OnStateChanged += new
axAppTunnel.OnConnected += new AxAPPCTRLLib._IAppTunnelEventsEx_OnConnectedEventHandler(axAppTunnel_OnConnected);
axAppTunnel.OnCheckSessionComplete += new AxAPPCTRLLib._IAppTunnelEventsEx_OnCheckSessionCompleteEventHandler(axAppTunnel_OnCheckSessionComplete);
}
[STAThread]
static void Main(string[] args)
{
try
{
axAppTunnel = new AxAPPCTRLLib.AxAppTunnelEx();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Resource1));
axAppTunnel.Enabled = true;
axAppTunnel.Name = «axAppTunnel»;
axAppTunnel.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject(«axAppTunnel.OcxState»)));
axAppTunnel.TabIndex = 0;
axAppTunnel.Visible = false;
string HostName = «firepasshost»;
int Port = 443;
string UserName = «usernm»;
string Password = «password»;
((System.ComponentModel.ISupportInitialize)axAppTunnel).EndInit(); ;
axAppTunnel.CreateControl();
// Open new server session
axAppTunnel.OpenSession(HostName, Port, UserName, Password);
// Close server session%
axAppTunnel.CloseSession();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
private void axAppTunnel_OnOpenSession(object sender, AxAPPCTRLLib._IAppTunnelEventsEx_OnOpenSessionEvent e)
{
Console.WriteLine(«opened session successfully»);
}
}
}
Hi, We are developing a WPF based Engine application. In this application, we have tab controls, which have a WindowsFormsHost, which holds the instance of the mapcontrol.
When we switch between the tabs, we remove the mapcontrol from the previous windows formshost and place it in the current tab page’s windows form host.
Further, we are setting some properties of the mapcontrol.
In certain cases, when i set the properties of the mapcontrol, i get this error: ‘System.Windows.Forms.AxHost+InvalidActiveXStateException’ .
I learnt that this error arises when the mapcontrol instance exists but is not held by any container that can draw it.
What i wanted to know was, is there any way to know the activeXState of the mapcontrol? Just checking whether the mapcontrol is null isnt helpful.
Thanks.
Hi Avinash,
If you don’t want to add new control then you need not create a new chart Object. You can do the same as following way:
FC.Movie =
Application.StartupPath + «FusionChartsFCF_Bar2D.swf?chartWidth=» + FC.Width.ToString() + «&chartHeight=» + FC.Height.ToString();
//dataXML method
FC.SetVariable(
«dataXML»,«<graph><set value=’10’ /></graph>»);
//dataURL method
FC.SetVariable(«dataURL», «Path to XML file»);
Otherwise try this:
int oldHeight = FC.Height;
int oldWidth = FC.Width;
int oldTop = FC.Top;
int oldLeft = FC.Left;
FC.Dispose();
FC = new AxShockwaveFlashObjects.AxShockwaveFlash();
FC.Height = oldHeight;
FC.Width = oldWidth;
FC.Top = oldTop;
FC.Left = oldLeft;
this.Controls.Add(FC);
FC.Movie =
Application.StartupPath + «FusionChartsFCF_Bar2D.swf?chartWidth=220&chartHeight=300»;
FC.MovieData = chartURL;
FC.Play();