There's nothing wrong with your C# class implementing a Dispose method and
having your COM clients call it, but:
1. Dispose is typically just between .NET code. The class implements
IDisposable, clients can test for that Interface and call Dispose().
2. You have to implement it. Your example Dispose just called itself until
it overflowed the stack.
3. What resources does your C# class own that makes you think you need to
use Dispose?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
conimplementingdisposemethod.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/c
pconFinalizeDispose.asp

Signature
Phil Wilson
[Microsoft MVP-Windows Installer]
Definitive Guide to Windows Installer
http://apress.com/book/bookDisplay.html?bID=280
> Forgive me for I'm still quite new to this, but what would be the best
> way to go about releasing a .NET class instantiated from a VB6
> application then?
koojo31@hotmail.com - 15 Dec 2004 18:08 GMT
Well, here's my scenario:
I have an extension (toolbar created in VB6) to an application. I want
to include some .NET controls in the extension (ie. the user clicks on
a button on the toolbar and the extension calls a .NET class which
opens a .NET form with .NET controls). This class also handles events
that are raised from the application (I pass a reference to the
application from the VB6 extension to the .NET class). Now, when the
user closes the .NET form, I want all references to the application to
be cleared so that the event doesn't fire in the .NET class anymore.
However, in my situation the event is still firing from the .NET class
even after directly calling the Dispose method (below) from VB6.
(Although I no longer get the StackOverflowException).
~clsWindow()
{
Dispose(false);
}
// Implement IDisposable.
// Do not make this method virtual.
// A derived class should not be able to override this method.
public void Dispose()
{
Dispose(true);
// Take yourself off the Finalization queue
// to prevent finalization code for this object
// from executing a second time.
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if(!this.disposed)
{
// If disposing equals true, dispose all managed
// and unmanaged resources.
if(disposing)
{
// this object is a .NET form called by the .NET class
m_objNETWindow.Dispose();
}
// These objects were passed in from the VB6 application
Marshal.ReleaseComObject(m_pAVEvents);
Marshal.ReleaseComObject(m_pMxDoc);
Marshal.ReleaseComObject(m_pMap);
}
disposed = true;
}