System.Windows.Media.DrawingVisual.RenderOpen()一段时间后出错

Dan*_*ley 15 .net iis wpf rendering system.windows.media

使用案例:我正在使用WPF在Web上下文中动态覆盖图像上的文本.

解决方案:我使用的是DrawingContextDrawingVisual(包裹在一个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 ...
Run Code Online (Sandbox Code Playgroud)

临时修复:唯一的解决方法是在服务器上回收IIS应用程序池,将问题解决几个小时.

问题:任何人都想过这个问题的原因(泄漏,线程,非托管代码等)?有没有其他方法可以在图像上获取文本,避免绘图视觉?也许将几何图形写入位图并直接覆盖位图?

小智 1

这是一个旧补丁 - 我认为它包含在 .NET 4.x 中 - 但我不太确定。无论如何 - 你可以尝试一下。

»讨论和错误报告

» .NET 补丁(x86)