1

I have this issue with a WinForms project using forms with complex controls.
With a certain degree of complexity (e.g. controls number), WinForms can become very slow, this I know.
So to get reasonable display performance, Application.VisualStyleState is disabled:
Application.VisualStyleState = System.Windows.Forms.VisualStyles.VisualStyleState.NoneEnabled;

Using the faster "Windows classic theme" makes the WinForms controls performance bearable (unfortunately the generally desirable WPF port is not in scope).

Now on Win10 systems (no issue on Win7), WinForms FileDialog controls called by the app do show an "empty" context menu for right-clicked items:
enter image description here

I am okay with the 'old' Win7 style in general by the way. My concern is just the empty context menu.

Attempts for alternatives using a WPF FileDialog or a WindowsAPICodePack FileDialog throw both this exception:
"Creating an instance of the COM component with CLSID {DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7} from the IClassFactory failed due to the following error: 80040111 ClassFactory cannot supply requested class (Exception from HRESULT: 0x80040111 (CLASS_E_CLASSNOTAVAILABLE))."

Any suggestions how to get the context menu entries back for my scenario using the WinForms FileDialog on Win10?
Or how to make one of the alternatives work (I know they all call the same native WIN32 functions)?

Rotax
  • 77
  • 9
  • I suspect you've run out of User32 or GDI objects in your process. What does Task Manager say about the number of "User objects" and "GDI objects" in your process? (they're in columns that are hidden by default in the Details tab). – Dai Jan 25 '20 at 12:05
  • btw - this will only be a problem if you have more than a 1,000 windowed controls in your form. But if you're doing that then you're probably doing something very wrong. How many `Control` instances do you have in your `Form`? You don't need to port to WPF to reduce your hWnd count. – Dai Jan 25 '20 at 12:06
  • @Dai: The number of controls is high in some forms/cases (using nested panels/groupboxes structures), but even when the "User objects"/"GDI objects" count is low (<100), the issue occurs. The issue seems to be unrelated with the controls count, I just made the comment about the complex/high controls usage to explain the disabling of Application.VisualStyleState. If enabled, the FileDialog is shown without issues. Alas, enabling Application.VisualStyleState is not an option. :( – Rotax Jan 25 '20 at 12:32
  • 1
    This dialog is known to be troublesome when visual styles are disabled. You'll probably have to go whole-hog and also use the legacy version of the dialog. https://stackoverflow.com/questions/29929862/exception-from-hresult-0x80040111-class-e-classnotavailable – Hans Passant Jan 25 '20 at 13:04
  • @HansPassant: With the information [link](https://stackoverflow.com/questions/29929862/exception-from-hresult-0x80040111-class-e-classnotavailable) you provided I cannot make out how to use a legacy version of FileDialog... Please, could you elaborate? – Rotax Jan 25 '20 at 14:44
  • https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.filedialog.autoupgradeenabled?view=netframework-4.8 – Hans Passant Jan 25 '20 at 15:13
  • @HansPassant: I tried that too, but setting AutoUpgradeEnabled=false did not make the context menu show correctly on Win10 with visual styles disabled... WPF approach: Also I have found this [pull request](https://github.com/dotnet/winforms/pull/2515) - but this would only impact .NET Core, right? – Rotax Jan 25 '20 at 15:22
  • Try this on another machine, the cleaner the better. If that works then fix your own machine with SysInternals' AutoRuns, disable shell extensions that don't have a Microsoft copyright. – Hans Passant Jan 25 '20 at 15:24
  • 1
    https://github.com/dotnet/winforms/ is only for .NET Core/.NET. – RussKie Jan 26 '20 at 10:50
  • @RussKie: Yes, unfortunately - assuming this would also resolve the issue of getting the COMException when using the WPF FileDialog with a regular Winforms app call - when having visual styles disabled as cause. I do also not know if it then would show the correct context menu - for this being the actual original issue here. – Rotax Jan 26 '20 at 13:21
  • @HansPassant: I am afraid that I would (and do) see the behaviour on a clean machine (I use a fresh Win10 install for testing->issue is present) - and the reports also come in from customers anyways, where the system setup is out of reach. So is this a dead end for now (until a native Filedialog functionality fix is provided)? – Rotax Jan 26 '20 at 13:30
  • Can you create a small repro on .NetCore? If so, that's something you can debug. – RussKie Jan 27 '20 at 21:44
  • @RussKie: ...That would probably be asking too much, given my resourcefulness :( – Rotax Jan 29 '20 at 08:51

0 Answers0