Trying to use a COM visible .NET class via other .NET application and get exception:
Message: The object's type must be __ComObject or derived from __ComObject.
Parameter name: o
Stack Trace: at System.Runtime.InteropServices.Marshal.ReleaseComObject(Object o)
The class looks as follows:
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IViewer : IComInteropDefinedInterface
{
}
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
[Guid("[some guid]")]
public class MyViewer : UserControl, IViewer
{
//IViewer implementation
}
I register the component with:
regasm [Assembly Path] /tlb /codebase
The client application, which is also in .NET instantiates successfully the given class, but when he callsMarshal.ReleaseComObject()
it gets the exception described above.
Any idea for solving this problem?
EDIT: Unfortunately I can't provide the client application code for instantiating my object. However I know the client is using the same method to instantiate real COM objects.
But how are you creating the class instance? Simply using the expression
new MyViewer()
doesn't create a COM object. Instead it creates a plain old .Net object which cannot be used with the ReleaseComObject method.Based on your sample code, in particular the line about
MyViewer
having an implementation, it doesn't sound like you're dealing with a COM object. Instead it looks like you have a managed object which implements a COM interface.In order to use the ReleaseComObject you'd need to actually have a COM / RCW object.