[IronPython] COM Interop / Dispose wierdness

Dan Shechter dans at houmus.org
Mon Apr 17 12:38:26 CEST 2006


Hi,
I have a c# class which is a wrapper around the WMF (Windows Media Format)
SDK.
One of the classes, which wraps the IWMMetadataEditor interface roughly
looks like this:
namespace WMFSDKWrapper
{
    public class MetadataEditor : IDisposable, IEnumerable
    {
    	  bool isDisposed = false;
    	  private IWMMetadataEditor editor;
	  ...

        public void Flush()
        { editor.Flush(); }

        private void Dispose(bool disposing)
        {
            if (!isDisposed)
            {
                if (disposing)
			; // No managed resources to clear up...
                // Clear up unmanaged resources
                Flush();
            }
            isDisposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        ~MetadataEditor()
        { Dispose(false); }
    }
}

Now, the wrapper (which obviously has more code) works perfectly.
I can change a WM file's metadata or query it as I wish.
I can call the Flush(), Close() or even Dispose() method directly and they
all work fine...
i.e.: If I call the Dispose() method "manually" I get:
IronPython 1.0.2281 (Beta) on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import wmf
>>> m = wmf.MetadataEditor("a.wma")
>>> m[wmf.MediaMetadata.Title]
'123'
>>> m.Dispose()
>>> ^Z
(IronPythonConsole.exe exits cleanly)

The problem I'm getting is that if exit the IronPython console without
calling the object's Dispose method beforehand I get
Something like this, regardless of what I did with the COM object (i.e.,
read-only or read-write):
IronPython 1.0.2281 (Beta) on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import wmf
>>> m = wmf.MetadataEditor("a.wma")
>>> m[wmf.MediaMetadata.Title]
'123'
>>> ^Z
Unhandled exception:
Traceback (most recent call last):
  File WMFSDKWrapper, line unknown, in Finalize
  File WMFSDKWrapper, line unknown, in Dispose
  File WMFSDKWrapper, line unknown, in Flush
  File WMFSDKWrapper, line unknown, in Flush
TypeError: Unable to cast COM object of type 'System.__ComObject' to
interface type 'WMFSDKWrapper.IWMMetadataEditor'. T
his operation failed because the QueryInterface call on the COM component
for the interface with IID '{96406BD9-2B2B-11D
3-B36B-00C04F6108FF}' failed due to the following error: No such interface
supported (Exception from HRESULT: 0x80004002
 (E_NOINTERFACE)).

Unhandled Exception: System.InvalidCastException: Unable to cast COM object
of type 'System.__ComObject' to interface ty
pe 'WMFSDKWrapper.IWMMetadataEditor'. This operation failed because the
QueryInterface call on the COM component for the
 interface with IID '{96406BD9-2B2B-11D3-B36B-00C04F6108FF}' failed due to
the following error: No such interface suppor
ted (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
   at WMFSDKWrapper.IWMMetadataEditor.Flush()
   at WMFSDKWrapper.MetadataEditor.Flush()
   at WMFSDKWrapper.MetadataEditor.Dispose(Boolean disposing)
   at WMFSDKWrapper.MetadataEditor.Finalize()

	Any ideas?
	Shechter.





More information about the Ironpython-users mailing list