Nope, no guaranteed order... The problem here is it could be a problem w/ the order of two unmanaged objects which are being "finalized" in some arbitrary order because the GC is cleaning them up.
Another possibility that occurred to me is that there could be a violation of COM rules by WMF which the CLR only hits at shutdown. In particular I'm thinking of the aggregation rules where if you QI an object implementing IFoo for interface IBar and it succeeds then QIing IBar for IFoo must succeed. I've recently been told that the CLR cares about objects following this rule a lot, so maybe you hit this at shutdown but not at runtime. But again, it's a WMF issue :) Hopefully you'll have good luck w/ the WMF forums. 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: Thursday, April 20, 2006 8:59 AM To: 'Discussion of IronPython' Subject: Re: [IronPython] COM Interop / Dispose wierdness OK, I pretty much get what you're aiming for. You are saying that since there is no deterministic order for Finalization the COM object (which implements IWMMetaDataEditor) may be disposed of BEFORE my "Wrapper" Finalizer get's called. But shouldn't the order be enforced by someone (CLR that is) so that AT LEAST the managed components get finalized and destroyed BEFORE the unmanaged ones? I seem to remember there should be some thing like this... I'll dig deeper and also post in the WMF forums, Thanks, Shechter. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dino Viehland Sent: Monday, April 17, 2006 18:24 To: Discussion of IronPython Subject: Re: [IronPython] COM Interop / Dispose wierdness 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-11F 0-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 _______________________________________________ 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