10

In my WPF application on .NET 4.0, I am having users report two errors that seem very intermittent and I cannot get a handle on. Below, I am posting the message and the top-most line of the stack trace. I can post the full stack trace if needed.

Message:       {Desktop composition is disabled} The operation could not be completed because desktop composition is disabled. (Exception from HRESULT: 0x80263001)
StackTrace:    at Standard.NativeMethods.DwmExtendFrameIntoClientArea(IntPtr hwnd, MARGINS& pMarInset)

Message:       Insufficient memory to continue the execution of the program.
StackTrace:    at System.Windows.Media.Composition.DUCE.Channel.SyncFlush()

Google is not proving very helpful, so I was hoping maybe you guys have seen them before.

Ian Gregory
  • 5,770
  • 1
  • 29
  • 42
TrialAndError
  • 1,784
  • 3
  • 20
  • 41

2 Answers2

15

I finally was able to nail down the issue - graphics adapter driver.

This post, along with this one helped me figure it out. Basically, what happened is I had 4 users (out of about 600) that were experiencing issues. They also reported that their screens would flicker at random times and some reported 'task bars turning solid'. This would be what caused the DWM composition error, and apparently if they had multiple programs running that were intensively using the graphics card, it would run out of memory.

I tested using Geeks3d.com FurMark benchmarking program to max out the graphics card then launched my application. It would crash upon opening and throw the outofmemory exception, so I know it wasn't a memory leak.

After updating the driver, I was unable to generate the crash...even with multiple programs AND FurMark running at full blast.

Hopefully this helps someone down the road.

TrialAndError
  • 1,784
  • 3
  • 20
  • 41
6

The first error is related to the Aero Glass style that you are using in your WPF Window. When the user turns the glass theme off (and uses the basic theme) these Glass methods like DwmExtendFrameIntoClientArea fail. You therefore need to check whether Desktop Window Manager (DWM) composition is enabled:

[DllImport("dwmapi.dll", PreserveSig = false)] 
public static extern bool DwmIsCompositionEnabled(); 

The second problem seems to be an unmanaged bug. Check this very elaborate answer on another very similar question: https://stackoverflow.com/a/1965382/1255010

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
dsfgsho
  • 2,731
  • 2
  • 22
  • 39
  • I don't have any particular Aero Glass style, at least I haven't done anything other than a default WPF application. From what I have seen, this is done fairly explicitly, so I would know if I was using a glass style...or is this glass style by default in WPF? – TrialAndError Jun 20 '13 at 14:53
  • Are you sure? Are you using any special libraries or components? The error clearly indicates the problem is caused by `DwmExtendFrameIntoClientArea` which is not used in a standard WPF window. – dsfgsho Jun 20 '13 at 14:56
  • What is really strange about it is that I can go into my system settings and disable desktop composition and have been completely unable to replicate on demand. I will have to make sure I don't have some obscure library somewhere that could be using it. On top of that, the two exceptions are generally reported together (users seeing one of them are seeing the other as well). – TrialAndError Jun 20 '13 at 15:30
  • Can you give some more details on the context/use/purpose of the application and also when the exceptions are thrown? – dsfgsho Jun 20 '13 at 15:43
  • The application is used with a few web services and databases to provide a 'dashboard' of information. I am also using Prism/Unity to make it a composite application comprised of various modules. The crash seems to be occurring when the window is resized/moved, but seemingly randomly. They can resize all day, but then suddenly it will crash and they are unable to reproduce. Sometimes, they will be away from their computer for awhile, come back, resize the window and it crashes. It seems to be isolated to resizing/moving the window. – TrialAndError Jun 20 '13 at 16:12