15

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?

STiLeTT
  • 1,023
  • 10
  • 23
Daniel Bradley
  • 1,120
  • 1
  • 12
  • 22
  • 1
    I'm having a similar problem: http://stackoverflow.com/questions/5195808/wpf-formattedtext-the-system-cannot-find-the-file-specified-exception-in-a-serv – AlignedDev Mar 29 '11 at 14:52
  • Can you share a code snippet of how you're getting the DrawingContext and the DrawingVisual? Why not just recycle the DrawingVisual? Are you allowing the Dispatcher to pump? – justin.m.chase Sep 25 '11 at 14:48
  • I know this is an old question, however does the process leak memory or handles? Seems maybe a hang dump would help get to the root of the problem? – Nathan Rice Apr 09 '12 at 23:41

1 Answers1

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)

Jeremy W
  • 51
  • 3