System.Windows.Media.DrawingVisual.RenderOpen() 一段时间后出错
用例:我使用 WPF 在 Web 上下文中的图像上动态覆盖文本。
解决方案: 我使用来自 DrawingVisual
的 DrawingContext
(包含在 using
语句中)来绘制原始位图和覆盖文本。
问题:在数千个请求之后,[DrawingVisual].RenderOpen()
方法开始拒绝执行并引发以下异常:
The system cannot find the file specified System.ComponentModel.Win32Exception UInt16 RegisterClassEx(WNDCLASSEX_D) at MS.Win32.UnsafeNativeMethods.RegisterClassEx(WNDCLASSEX_D wc_d)
at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
at System.Windows.Media.MediaContextNotificationWindow..ctor(MediaContext ownerMediaContext)
at System.Windows.Media.MediaContext..ctor(Dispatcher dispatcher)
at System.Windows.Media.MediaContext.From(Dispatcher dispatcher)
at System.Windows.Media.Visual.VerifyAPIReadWrite()
at System.Windows.Media.DrawingVisual.RenderOpen()
at ...
临时修复:对此的唯一修复是回收 IIS 应用程序池服务器修复了问题几个小时。
问题:有人对这个问题的原因(泄漏、线程、非托管代码等)有想法吗?有没有其他方法可以在图像上获取文本以避免绘图视觉效果?也许将几何图形写入位图并直接覆盖位图?
Use Case: I'm using WPF to dynamically overlay text on images within a web context.
Solution:
I'm using a DrawingContext
from a DrawingVisual
(wrapped in a using
statement) to draw the original bitmap and overlay text.
Problem: After a few thousand requests the [DrawingVisual].RenderOpen()
method starts refusing to execute and throws the following exception:
The system cannot find the file specified System.ComponentModel.Win32Exception UInt16 RegisterClassEx(WNDCLASSEX_D) at MS.Win32.UnsafeNativeMethods.RegisterClassEx(WNDCLASSEX_D wc_d)
at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
at System.Windows.Media.MediaContextNotificationWindow..ctor(MediaContext ownerMediaContext)
at System.Windows.Media.MediaContext..ctor(Dispatcher dispatcher)
at System.Windows.Media.MediaContext.From(Dispatcher dispatcher)
at System.Windows.Media.Visual.VerifyAPIReadWrite()
at System.Windows.Media.DrawingVisual.RenderOpen()
at ...
Temp fix: The only fix for this is to recycle the IIS application pool on the server which fixes the problem for a few hours.
Question: Anyone have a thought on the cause of this issue (leaks, threading, unmanaged code etc)? Is there any other way of getting text on an image avoiding the drawing visual? Perhaps writing geometry to a bitmap and overlaying the bitmaps directly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个旧补丁 - 我认为它包含在 .NET 4.x 中 - 但我不太确定。无论如何 - 你可以尝试一下。
» 讨论与讨论错误报告
».NET 补丁(x86)
This is an old patch - and I would have assumed it was included in .NET 4.x - but I'm not so sure. Anyways - You can give it a shot.
» Discussion & Bug Report
».NET Patch(x86)