TargetInvocationException: Microsoft.AGL.Common.MISC.HandleAr (PAL_ERROR ar)

I get a TargetInvocationException randomly when loading resources in my .NET Compact Framework 3.5 project (works on Windows Mobile 6). They look like 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 this exception is that there is an unmanaged resource that I forgot to clear. However, I have many forms and resources in my project.

So here are my questions:

  • Can there be a reason or exception for a form or resource that has not been cleared?
  • How can I track the exact form or resource that is taking my memory?

Relative 2: I have already profiled my application using 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 do not see where these resources are used. How can I find out?

+4
source share
1 answer
  • Yes
  • I wish (And do not even try to claim power toys, the profiler will help you).

You will need to view your code. Make sure you call 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 p / to call DeleteObject to clear after it. (Managed call requires p / invoke not to leak resources)

My only advice: for some reason, most of the time, my AGL errors are close to the source of the problem. I can’t remember the specific reasons. At work, we call it the undocumented “Accelerated Layer of Sorrow (AGL)”

Finally, I have another hot question. You select many raster images at the same time, then free them up and finally try to create managed memory objects, possibly buffers? Windows Mobile 6 is built from Windows CE 5.0, not Windows CE 6.0. Therefore, each process has a limit of 32 MB for memory. If you select many raster images at the same time, they increase the size of the unmanaged heap. When you delete bitmaps, LocalFree and the decommit heap are called, but do not free memory, and .NET will never see it again. The only way to avoid this, except to avoid allocating a large number of raster images at once, is to select raster images that are greater than or equal to 96 KB that reserve pages outside the heap.

It is probably doubtful that this is your problem, but I mentioned this because it is almost impossible to track. However, I think that in this case you would encounter a crash or an OutOfMemoryException.

Anyway, I would like to make sure that you are not leaking resources or pens, and double check that your stream is in the correct format.

+3
source

Source: https://habr.com/ru/post/1447505/


All Articles