TargetInvocationException:Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR AR) [英] TargetInvocationException: Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR ar)

查看:1688
本文介绍了TargetInvocationException:Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR AR)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的.NET Compact Framework 3.5的项目加载资源时(在Windows Mobile 6上运行)获得TargetInvocationException随机。他们类似于此堆栈跟踪:

  FATAL 2012年11月13日14:17:00657 [23768895] TargetInvocationException  -  mobileX.MIP.Post presentation.Program
System.Reflection.TargetInvocationException:TargetInvocationException --->的System.Exception:异常
在Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR AR)
在System.Drawing.Bitmap._InitFromMemoryStream(MemoryStream的Mstream工具)
在System.Drawing.Bitmap..ctor(流流)
在System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo RTCI,的BindingFlags invokeAttr,活页夹粘结剂,对象参数,CultureInfo的文化,布尔isBinderDefault,大会来电,布尔verifyAccess,StackCrawlMark和放大器; stackMark)
在System.Reflection.RuntimeConstructorInfo.Invoke(的BindingFlags invokeAttr,粘合剂粘合,对象]参数,CultureInfo的文化)
在System.Reflection.ConstructorInfo.Invoke(对象[]参数)
在System.Resources.ResourceReader.CreateResource(类型OBJTYPE,类型[] ctorParamTypes,对象[] ctorParameters)
在System.Resources.ResourceReader.LoadBitmap(的Int32 typeIndex)
在System.Resources.ResourceReader.LoadObjectV2(的Int32 POS,的ResourceType code和;型code)
在System.Resources.ResourceReader.LoadObject(的Int32 POS,的ResourceType code和;型code)
在System.Resources.RuntimeResourceSet.GetObject(字符串键,布尔IGNORECASE)
在System.Resources.ResourceManager.GetObject(字符串名称,CultureInfo的文化)
 

我猜测这个异常的原因是,有,我忘了清理一些非托管资源。不过,我得到了很多的项目形式和资源。

因此​​,这里是我的问题:

  1. 难道还没有被清理表单或资源是有原因的异常?
  2. 如何跟踪的具体形式或资源会浪费我的记忆?

对于2:我已经异形我与CLR探查器应用程序从 .NET Compact Framework中的电动玩具3.5 的。大量的内存进入本地功能/ System.Windows.Forms.Control的:: _ InternalWnProc Microsoft.AGL.Common.PAL_ERROR(Microsoft.AGL.Forms.WM INT32 INT32)。但是,我不能看到这些资源的使用。我如何才能知道?

解决方案
  1. 我希望(甚至不尝试声称电源玩具分析器可以帮助你)

您将不得不审查你的code。请确保您调用Dispose上的所有可支配的对象包括所有的GDI对象,位图,画笔。

其次,如果你曾经打电话Font.ToHFont,这一呼吁是非常危险的,因为它需要你的P / Invoke DeleteObject后清理。 (A托管调用需要的AP /援引不泄漏资源)

我唯一的建议就是,由于某种原因,大部分时间我AGL错误发生接近问题的根源。我不记得具体原因。在工作​​中,我们称此为未公开的加速悲伤层(AGL)

最后,我有一个更尖锐的问题作出。你分配了大量位图一次,然后释放他们,最后试图创建托管内存中的对象,也许是缓冲区?的Windows Mobile 6内置关闭Windows CE 5.0,而不是的Windows CE 6.0。因此,每个进程都有一个32 MB的限制的内存。如果您分配了大量位图的同时,他们种植的非托管堆的大小。当您处理的位图,LocalFree被称为和堆decommit的,但不会释放内存和.NET将永远不会再看到它。要避免这种情况的唯一办法,不是避免在一次分配了大量位图等,是分配位图是大于或等于96 KB其保留堆之外的页面。

也许令人怀疑的是你的问题,但我会提到它,因为它几乎是不可能追查。我想,你最终会在这种情况下,碰撞或OutOfMemoryException异常,但是。

无论如何,我会去了解一下,确保你不会泄漏资源或处理,并仔细检查你的流是正确的格式。

I get a TargetInvocationException randomly when loading Resources in my .NET Compact Framework 3.5 project (running on Windows Mobile 6). They look similar to this stack trace:

FATAL 2012-11-13 14:17:00,657 [23768895] TargetInvocationException - mobileX.MIP.Post.Presentation.Program
System.Reflection.TargetInvocationException: TargetInvocationException ---> System.Exception: Exception
at Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR ar)
at System.Drawing.Bitmap._InitFromMemoryStream(MemoryStream mstream)
at System.Drawing.Bitmap..ctor(Stream stream)
at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
at System.Resources.ResourceReader.CreateResource(Type objType, Type[] ctorParamTypes, Object[] ctorParameters)
at System.Resources.ResourceReader.LoadBitmap(Int32 typeIndex)
at System.Resources.ResourceReader.LoadObjectV2(Int32 pos, ResourceTypeCode& typeCode)
at System.Resources.ResourceReader.LoadObject(Int32 pos, ResourceTypeCode& typeCode)
at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase)
at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture)

My guess for the reason of this exception is that there's some unmanaged resource which I forgot to clean up. However, I've got a lot of Forms and Resources in the project.

So here are my questions:

  1. Could a Form or Resource which has not been cleaned up be a reason for this exception?
  2. How can I trace the exact Form or Resource which wastes my memory?

Regarding 2: I already profiled my application with the CLR Profiler from the .NET Compact Framework Power Toys 3.5. A lot of memory goes to "NATIVE FUNCTION" / System.Windows.Forms.Control::_InternalWnProc Microsoft.AGL.Common.PAL_ERROR (Microsoft.AGL.Forms.WM int32 int32). However, I cannot see where these resources are used. How can I find out?

解决方案

  1. Yes
  2. I wish (And don't even try to claim the power toys profiler will help you)

You are going to have to review your code. Make sure you are calling Dispose on all Disposable objects including all GDI objects, bitmaps, brushes.

Secondly, if you ever call Font.ToHFont, this call is extremely dangerous because it requires you to p/invoke DeleteObject to clean up after it. (A managed call requires a p/invoke to not leak resources)

My only advice is that, for some reason, most of the time my AGL errors happen close to the source of the problem. I can't remember specific causes. At work, we call this the undocumented "Accelerated Grief Layer (AGL)"

Lastly, I have one more pointed question to make. Are you allocating a lot of bitmaps at once, then freeing them, and finally trying to create managed memory objects, perhaps buffers? Windows Mobile 6 is built off of Windows CE 5.0 and not Windows CE 6.0. Therefore, each process has a 32 MB limit for memory. If you allocate a lot of bitmaps at once, they grow the size of the unmanaged heap. When you dispose of the bitmaps, LocalFree is called and the heap decommit's but does not release the memory and .NET will never see it again. The only way to avoid this, other than avoiding allocating a lot of bitmaps at once, is to allocate bitmaps that are greater than or equal to 96 KB which reserves pages outside of the heap.

Probably doubtful that is your problem, but I'll mention it because it is nearly impossible to track down. I think you would end up with a crash or OutOfMemoryException in that case, however.

Anyhow, I would look into making sure you are not leaking resources or handles, and double check your stream is in the correct format.

这篇关于TargetInvocationException:Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR AR)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆