Hi,
A few weeks ago I implemented a bug tracker business object for my application. Whenever an (unhandled) exception appears on the client machine, I write all available information like the stack trace into the database (I used to write this information only into the event log of the client computer). This way I noticed some strange exceptions that were not reproducible on first look and seemed only to appear when the application runs for a long time yet:
System.Drawing.Image get_Item(Int32)
System.Windows.Forms
InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index
at System.Windows.Forms.ImageList.ImageCollection.get_Item(Int32 index)
...
or
Void _SerializationInvoke(System.Object, System.SignatureStruct ByRef, System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)
mscorlib
Void .ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)
System.Windows.Forms
Exception has been thrown by the target of an invocation.
Loading of the ImageList did not succeed.
at System.RuntimeMethodHandle._SerializationInvoke(Object target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context)
...
I found this old posting from 2002 that describes the problem very well:
“The ImageList saves its images using the ImageListStreamer object
(which in turn uses the win32 function ImageList_Write). When the form
is created, an ImageListStreamer object is deserialized from the
resources, which is set to the ImageList.ImageStream property. The
problem comes in during the set_ImageStream method: neither the
ImageList nor the ImageListStreamer take responsibility for freeing
the created GDI imagelist object. The ImageList explicity sets a flag
so that it does NOT free this handle. The ImageListStreamer object
does not have a finalizer (nor is it disposable), so there is no
chance to free this GDI handle.“
Even though this posting is from 2002, I have found no solution for this problem. Sure, avoiding and removing the ImageLists helps – that’s what I did, but I have a few Treeviews and Listviews, where this isn’t possible.
Has anybody else recognized this strange behaviour? What have you done against it?
Thanks,
Christian
PS: Visual Studio 2005
I have removed all ImageLists where it was possible, and I set up the Treeview’s and Listview’s ImageLists in code now. But we use a third party print preview control and this control has got a ToolBar - and this ToolBar has got an ImageList. Avoiding ImageLists at all circumstances doesn’t seem to be possible...
Thank you very much for your help.
I found the following knowledge base article about the memory leak (from October 2005):
http://support.microsoft.com/kb/813967/en-us
But I was wondering, if it really only applies to .NET 1.0 SP 2...
Copyright (c) Marimer LLC