Windows Develop Bookmark and Share   
 index > Windows Forms General > exception during axhost.dispose
 

exception during axhost.dispose

when I create an activeX control at runtime which in fact is a .net control exposed as a com object, the hosting axhost class gets the following exception during its dispose:

The object's type must be __ComObject or derived from __ComObject.
Parameter name: o

When the activeX control is created by other means (e.g. visual basic 6.0) the dispose works fine.

The control is created by callingnew AxHost(CLSID_OF_THE_CONTROL)

Is the .net control missing any necessary interface implementation to work with axhost?

nagual  Tuesday, January 02, 2007 2:48 PM
You're doing something quite unusual of course. Can you show us the call stack please?
nobugz  Wednesday, January 03, 2007 2:35 PM

System.ArgumentException was unhandled by user code
Message="The object's type must be __ComObject or derived from __ComObject.\r\nParameter name: o"
Source="mscorlib"
ParamName="o"
StackTrace:
at System.Runtime.InteropServices.Marshal.FinalReleaseComObject(Object o)
at System.Windows.Forms.AxHost.ReleaseAxControl()
at System.Windows.Forms.AxHost.TransitionDownTo(Int32 state)
at System.Windows.Forms.AxHost.DisposeAxControls()
at System.Windows.Forms.Control.DisposeAxControls()
at System.Windows.Forms.Control.Dispose(Boolean disposing)
at System.Windows.Forms.ContainerControl.Dispose(Boolean disposing)
at System.Windows.Forms.Form.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at System.Windows.Forms.Application.ThreadWindows.Dispose()
at System.Windows.Forms.Application.ThreadContext.DisposeThreadWindows()

It might by unusual, anyway AxHost should be able to handle all ActiveX controls. Instantiating it works fine, just the dispose is the problem (unfortunatley thisis a showstopper as the window is not closing anymore after this exception)

nagual  Wednesday, January 03, 2007 5:15 PM
You get this failure when the marshaler tries to cast the wrapped ActiveX object (AxHost.GetOcx() returns it) to __ComObject. I haven't got a clue why that would fail, __ComObject is the base class type for any wrapped ActiveX object. Smells like a problem with the wrapper you created for the component with tlbimp.exe...
nobugz  Wednesday, January 03, 2007 5:37 PM

I don't have a wrapper as the activeX control is created dynamically during runtime, so the only thing I have is the CLSID, which is used to construct the AxHost object

nagual  Thursday, January 04, 2007 7:09 PM
That would explain it. Make a wrapper: Project + Add Reference, COM tab, select your component. That will automatically create two wrappers for the component, one of which is an AxHost derived one.
nobugz  Thursday, January 04, 2007 7:51 PM

Thats not the desired solution, as I want to be in principle independent of the activeX control. The interfaces shall be retrieved using reflection, not using a wrapper.

On the other hand AxHost is capable of disposing an activeX control which was build for instance with Visual Basic 6.0.

nagual  Friday, January 05, 2007 8:27 AM

You can use google to search for other answers

Custom Search

More Threads

• basic forms question
• Mapping Image Regions
• topmost, transparent form (using transparencyKey) with a usercontrol in its center
• The most rational programming of "changed" controls
• [Advanced] GDI+ Rendering in multiple threads
• adding a wav file to a button click event
• How to capture a "back Tab" (Shift+Tab) key?
• Determine if the point is in the polygon, C#
• Low level error handling
• Get parent window vb.net