Known issue: WPF will throw COM Exception when create RenderTargetBitmap too fast
See original GitHub issue- .NET Core Version: 3.1.300
- Windows version: 10.0.18362
- Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
Problem description:
When we use RenderTargetBitmap to take the control screenshots, if our do it too frequent and too fast, then we will find that the framework throws an exception.
Actual behavior:
System.Runtime.InteropServices.COMException: MILERR_WIN32ERROR
System.Runtime.InteropServices.COMException (0x88980003): MILERR_WIN32ERROR (Exception from HRESULT:0x88980003)
in System.Windows.Media.Imaging.RenderTargetBitmap.FinalizeCreation()
in System.Windows.Media.Imaging.RenderTargetBitmap..ctor(Int32 pixelWidth, Int32 pixelHeight, Double dpiX, Double dpiY, PixelFormat pixelFormat)
Expected behavior:
No exception
Minimal repro:
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Memory leak in RenderTargetBitmap
The leak seems to occur on the RenderTargetBitmap.Render method exclusively, even the DrawingContext.DrawRectangle call doesn't noticeably ...
Read more >WorkspaceManager is Throwing Exception
Hello, I am getting this exception while using Manager.ApplyWorkspace. The parameter value must be greater than zero.
Read more >Windows Presentation Foundation (WPF) forum - RSSing.com
If I start creating the bitmaps too fast, the constructor of RenderTargetBitmap throws the exception: MILERR_WIN32ERROR (Exception from HRESULT: 0x88980003). I ...
Read more >The slow screen redraws on the movement of the mouse - WPF
How can I speed up rendering when moving the mouse? For example, I draw two perpendicular lines on the screen, passing through the...
Read more >WPF 使用RenderTargetBitmap 快速截图出现COMException ...
RenderTargetBitmap throws COM exception when created too fast: MILERR_WIN32ERROR ... 已经报告官方,请看Known issus: WPF will throw COM Exception when create ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The workaround without forcing the GC is to manually release the handle in the RenderTargetBitmap using reflection:
Yeah, from my experience if you are running a x64 process (not the default setting anymore) and have plenty of RAM, the finalizers do eventually start kicking in.
As for fix, the BitmapSource should be IDisposable and release the handle/IWICBitmap on disposal rather than in a finalizer.