This could be an order of finalization issue - if you let things shut down entirely then all the finalizers in the system would be eligible to be run at once. But if you dispose of the MetadataEditor by hand anything it depends upon won't have its finalizer run yet.
At shutdown time the CLR will run all remaining finalizers and we could be cleaning up in the "wrong" order (although there's really no right order, finalization is non-deterministic). I think you'd need to talk to the WMF SDK team about the issue as they'll understand better their finalization issues (or wrap dispose in a try/catch InvalidCastException block :) ). Do you want to help develop Dynamic languages on CLR? (http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038) -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dan Shechter Sent: Monday, April 17, 2006 3:38 AM To: 'Discussion of IronPython' Subject: [IronPython] COM Interop / Dispose wierdness 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. _______________________________________________ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ users mailing list users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com