Hello. I'm struggling programmatically adding an ActiveX control to a form using AxHost. One of my registered, functional ActiveX controls is throwing an InvalidOperationException in my form's InitializeComponent routine during the EndInit() call. The InitializeComponent routine Code Snippet and the Call Stack output are below. I have scoured MSDN and several online resources and can only guess the AxControl object for that control is not constructed properly, but again, that's a guess. Please share any ideas you can muster regarding what is causing (and resolves) this issue. Thanks! -Ti
Code Snippet
--------------------
void InitializeComponent(string progID)
{
ResourceManager resources = new ResourceManager(typeof(AxForm));
Type type = Type.GetTypeFromProgID(progID, true);
axCtl = new AxControl(type.GUID.ToString());
((ISupportInitialize)(axCtl)).BeginInit();
SuspendLayout();
axCtl.Enabled = true;
axCtl.Name = "axCtl";
axCtl.TabIndex = 0;
Controls.Add(axCtl);
Name = "AxForm";
try
{
((ISupportInitialize)(axCtl)).EndInit();
}
catch (System.InvalidOperationException e)
{
//Dunno - but the next Show() call will throw the same exception unless something is done here.
}
Resize += new EventHandler(AxForm_Resize);
ResumeLayout(false);
OnResize();
try
{
Show();
}
catch (System.InvalidOperationException e)
{
//Dunno x2 - but the form will not update & display with the loaded control unless something is done here.
}
}
Call Stack
----------
at System.Windows.Forms.AxHost.DepersistControl()
at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
at System.Windows.Forms.AxHost.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.AxHost.EndInit()
at AxForms.AxForm.InitializeComponent(String strProgId) in C:\projects\wrk\AxCtl\Form1.cs:line 213