C
Corey Alix
I am registering a managed class as a COM class via
RegistrationServices.RegisterAssembly, then I am instantiating that class
via CreateObject, then I am testing if the object is a COM instance via
Type.IsCOMObject. Surprisingly (to me) the return value is False.
This is a problem for me, because I am using managed code to write a OWC
spreadsheet addin, and memory allocated by the addin is not freed when the
spreadsheet is destroyed. I wanted to explicitly invoke
InteropServices.Marshal.ReleaseComObject, but it is failing, presumably
because the object returned by CreateObject() is, in some way, not a COM
class.
Can anyone explain why the IsCOMObject is returning False, and what I might
be able to do to make it return True?
Sub Main()
Dim lvType As System.Type = GetType(ComClassTest)
Dim lvRegistrationServices As New
Runtime.InteropServices.RegistrationServices()
lvRegistrationServices.RegisterAssembly(lvType.Assembly,
Runtime.InteropServices.AssemblyRegistrationFlags.None)
Runtime.InteropServices.RegistrationConnectionType.SingleUse)
Try
Dim lvObject As System.Object =
Microsoft.VisualBasic.CreateObject(lvRegistrationServices.GetProgIdForType(lvType))
Debug.Assert(True = lvObject.GetType.IsCOMObject, "CreateObject
creates a COM object") ' this assertion fails
Finally
lvRegistrationServices.UnregisterAssembly(lvType.Assembly)
End Try
End Sub
RegistrationServices.RegisterAssembly, then I am instantiating that class
via CreateObject, then I am testing if the object is a COM instance via
Type.IsCOMObject. Surprisingly (to me) the return value is False.
This is a problem for me, because I am using managed code to write a OWC
spreadsheet addin, and memory allocated by the addin is not freed when the
spreadsheet is destroyed. I wanted to explicitly invoke
InteropServices.Marshal.ReleaseComObject, but it is failing, presumably
because the object returned by CreateObject() is, in some way, not a COM
class.
Can anyone explain why the IsCOMObject is returning False, and what I might
be able to do to make it return True?
Sub Main()
Dim lvType As System.Type = GetType(ComClassTest)
Dim lvRegistrationServices As New
Runtime.InteropServices.RegistrationServices()
lvRegistrationServices.RegisterAssembly(lvType.Assembly,
Runtime.InteropServices.AssemblyRegistrationFlags.None)
Runtime.InteropServices.RegistrationConnectionType.SingleUse)
Try
Dim lvObject As System.Object =
Microsoft.VisualBasic.CreateObject(lvRegistrationServices.GetProgIdForType(lvType))
Debug.Assert(True = lvObject.GetType.IsCOMObject, "CreateObject
creates a COM object") ' this assertion fails
Finally
lvRegistrationServices.UnregisterAssembly(lvType.Assembly)
End Try
End Sub