Desktop Composition Is Disabled Error

9

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.

c#
wpf
asked on Stack Overflow Jun 19, 2013 by TrialAndError • edited Aug 11, 2017 by Ian Gregory

2 Answers

14

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.

answered on Stack Overflow Aug 1, 2013 by TrialAndError
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

answered on Stack Overflow Jun 19, 2013 by dsfgsho • edited Mar 2, 2020 by Wai Ha Lee

User contributions licensed under CC BY-SA 3.0