问题
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?
回答1:
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)
来源:https://stackoverflow.com/questions/4716435/system-windows-media-drawingvisual-renderopen-erroring-after-a-time