本鱼拟成立工作室承接项目开发/软件定制/云设施开发运维/办公设备技术支持等,如您有相关需求,欢迎来询 | ::博客文章推荐::

Failed to load ImageList:加载ImageList数据流出错

: DOT.NET 木魚 3511℃ 2评论

昨天下午做程序,遇到一个问题,折腾了一个下午也没有折腾出来,到处问也没有人会。
今天早上突然想用Google搜搜外国的论坛吧,终于在外国的一个论坛中发现了这个问题的答案!
唉,感动的要死啊,还是google好!

记录如下:

———————————————————————————–
<div style='background:#f8f8f8; border:1px solid #efefef; border-radius: 5px; padding:10px; margin: 10px;'>When opening a non-modal dialog form which has an ImageList that I use
for a Treeview, the program crashes. This does not occur consistently,
but certainly often enough to be very annoying. It has happened two days
in a row now for one user.

The exception trace suggests to me that the .NET Framework is attempting
to extract the bitmaps from the DLL resources, or such?

It appears to be happening before any user code is being called. I have
seen others report this problem, but never a resolution. It would seem
to be a Framework bug to me. But maybe there is something I am doing?
Any clue why this could be happening, or more importantly, what I can do
about it?

************** Exception Text **************
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. —> System.InvalidOperationException:
Failed to load ImageList.
at System.Windows.Forms.ImageListStreamer..ctor(SerializationInfo
info, StreamingContext context)
— End of inner exception stack trace —
at
System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object
target, SerializationInfo info, StreamingContext context)
at
System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object
obj, SerializationInfo info, StreamingContext context)
at
System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder
holder)
at System.Runtime.Serialization.ObjectManager.DoFixups()
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler
handler, __BinaryParser serParser, Boolean fCheck, IMethodCallMessage
methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream
serializationStream, HeaderHandler handler, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream
serializationStream)
at System.Resources.ResourceReader.LoadObject(Int32 pos)
at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean
ignoreCase)
at System.Resources.ResourceManager.GetObject(String name,
CultureInfo culture)
at System.Resources.ResourceManager.GetObject(String name)
at PPSManager.frmVolumeNavigator.InitializeComponent()
at PPSManager.frmVolumeNavigator..ctor()
at PPSManager.frmMain.PrintVolumeNavaigator(Object sender, EventArgs e)
at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
at System.Windows.Forms.MenuItemData.Execute()
at System.Windows.Forms.Command.Invoke()
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
More information:

I found this article which describes the symptoms perfectly, but claims
it was a problem with Framework 1.0 SP2, and suggests it was
subsequently fixed:

http://support.microsoft.com/default.aspx?scid=kb;en-us;813967

But from the user's exception trace it would appear to me the user has
Framework 1.1 installed:
************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase:
file:///c:/winnt/microsoft.net/framework/v1.1.4322/mscorlib.dll

Can anyone shed light on if this problem has been re-introduced in
Framework 1.1, and if a patch is available anywhere to fix it?</div>

答案:
1.(这个就是我的问题的答案)
<div style='background:#f8f8f8; border:1px solid #efefef; border-radius: 5px; padding:10px; margin: 10px;'>Are you using an application manifest file with "devenv.exe"? </div>

2.
<div style='background:#f8f8f8; border:1px solid #efefef; border-radius: 5px; padding:10px; margin: 10px;'>No. Also, I am not deploying to XP.

But I think I found the problem, regardless. Coercing Bitmaps in an
Imagelist to an Icon seems to leak GDI resources. This was occuring for
5 small images on a polling cycle of 5 seconds. Performing all the
bitmap conversion work once at program start eliminates the leak, and
makes it more efficient at each poll/refresh anyway. When run overnight
the GDI object count was becoming staggering. Then when going to open
the form (as described above), it would then fall into the do-do left
for it.

The thing I learned this morning is the importantance of test-time
monitoring of the GDI OBJECTS COUNT in TASK MANAGER in order to detect
resource leaks in applications I am developing. I had never done this
before. </div>

喜欢 (0)
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(2)个小伙伴在吐槽
  1. 你看得懂就神了。。。

    木鱼2005-06-03 12:22 回复
  2. 看不懂

    果丁布冻2005-06-02 09:11 回复