I have a C# assembly that is COM-visible. It in turn communicates with a 3rd-party COM application. My problem is that when I release the reference to my C# assembly from VBA, the C# assembly keeps the 3-rd party application open.
' Call assembly from VBA
Dim asm : Set asm = CreateObject("MyCSharpAssembly")
' Get a managed object exposed by the assembly
' managedObject communicates with a 3-rd party COM application
Dim managedObject : Set managedObject = asm.GetManagedObject()
' When I release managedObject from VBA, the 3rd party application stays open.
Set managedObject = Nothing
I have tried implementing the IDisposable pattern in the managedObject and explicitly release the COM object. That works, but I still have to explicitly call the Dispose method from VBA. Just setting the reference to managedObject to Nothing is not enough. This is easily forgotten by VBA coders, who may assume setting the object to Nothing is enough.
Is there any way I can code around that from the C# perspective, or do I have to stick with the explicit Dispose?