0

I have a desktop app that has a small xaml window a third part is creating. They sent me sample code because they get a System.ComponentModel.Win32Exception that brings down the app. Their sample code is very simple. I have tried catching the exception too without success. Instead of catching the exception, I always get an Exception Unhandled message box (Visual Studio 2022 debugger) and the message is "Not enough quota is available to process this command."

The "command is a simple window.Show() call. This code works as we open a number of files and then it fails.

           try
        {
            var window = new System.Windows.Window
            {
                ResizeMode = ResizeMode.NoResize,
                Content = new EdgeBarPageView(),
                WindowStyle = WindowStyle.None
            };
            window.Show();

            return new WindowInteropHelper(window).Handle;
        }
        //catch (Exception e)
        //{
        //    MessageBox.Show(e.Message + "\n" + e.StackTrace, "GetEdgeBarView - Running GC and trying again.");
        //}
        catch (Win32Exception ex) when (ex.InnerException is Win32Exception)            //catch(System.ComponentModel.Win32Exception e)
        {
            MessageBox.Show(ex.Message + "\n" + ex.StackTrace, "GetEdgeBarView - Running GC and trying again.");
        }

At first I added the catch for Exception. But that failed. Then I added a catch below it for System.ComponentModel.Win32Exception. Visual Studio promptly warned me that the catch for Exception rendered the second catch useless as the Win32Exception is derived from Exception. I commented out catch( Exception ) and ran and I still can't catch it. I found code on stackoverflow that used "when" so I added that code (pasted above). Still I can't catch it.

When this occurs, I have a low GDI object count. I have about 100 gigs of memory available (32 gigs of ram on the box and 100gigs of swap for a total of 130 available with just shy of 32 gigs committed. The files I have a quite large as is our desktop c++ application.

The code for EdgeBarPageView is also simple.

    public partial class EdgeBarPageView : UserControl
{
    public EdgeBarPageView()
    {
        InitializeComponent();
    }
}

All I really care to do is catch the exception, which should be so easy to do.

Since comments are so limited, I was unable to paste in the generic code in reply to Charlie nor paste an image I got from the snipping too. So ...

enter image description here

No picture. Just the whole stack.

PresentationCore.dll!System.Windows.Interop.HwndTarget.UpdateWindowSettings Unknown
PresentationCore.dll!System.Windows.Interop.HwndTarget.UpdateWindowPos  Unknown
PresentationCore.dll!System.Windows.Interop.HwndTarget.HandleMessage    Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.HwndTargetFilterMessage  Unknown
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc    Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation   Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall  Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen  Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl    Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc   Unknown
[Native to Managed Transition]  
user32.dll!UserCallWinProcCheckWow  Unknown
user32.dll!DispatchClientMessage    Unknown
user32.dll!__fnINOUTLPPOINT5    Unknown
ntdll.dll!KiUserCallbackDispatcherContinue  Unknown
win32u.dll!NtUserSetWindowPos   Unknown
WindowsBase.ni.dll!00007ff971c778c1 Unknown
[Managed to Native Transition]  
PresentationFramework.dll!System.Windows.Window.Flush   Unknown
PresentationFramework.dll!System.Windows.Window.HwndStyleManager.System.IDisposable.Dispose Unknown
PresentationFramework.dll!System.Windows.Window.CreateSourceWindow  Unknown
PresentationFramework.dll!System.Windows.Window.ShowHelper  Unknown

Isap.Prototypes.UGSCallSampleNETAddin.dll!Isap.Prototypes.UGSCallSampleNETAddin.EdgeBarService.AddPage Line 128 C# Isap.Prototypes.UGSCallSampleNETAddin.dll!Isap.Prototypes.UGSCallSampleNETAddin.Addin.AddPage Line 216 C# [Native to Managed Transition]
jengined.dll!CProxyISEAddInEdgeBarEventsEx::Fire_AddPage Line 1038 C++ jengined.dll!CAddIn::FireAddPage Line 4605 C++ jengined.dll!JApplication::FireEdgeBarEvent Line 1357 C++ jengined.dll!JApplication::FireActiveDocumentChange Line 248 C++ jengined.dll!JTransitionDocs Line 7334 C++ jengined.dll!JWinLayer::OnSetFocus Line 5396 C++ jengined.dll!JWinLayer::WindowProc Line 3892 C++ jengined.dll!JWinLayer::WinLayerWindowProc Line 3812 C++ user32.dll!UserCallWinProcCheckWow Unknown user32.dll!DispatchClientMessage Unknown user32.dll!__fnDWORD Unknown ntdll.dll!KiUserCallbackDispatcherContinue Unknown win32u.dll!NtUserSetFocus Unknown jengined.dll!JApplication::ViewFrameWindowProc Line 414 C++ user32.dll!UserCallWinProcCheckWow Unknown user32.dll!DispatchClientMessage Unknown user32.dll!__fnDWORD Unknown ntdll.dll!KiUserCallbackDispatcherContinue Unknown win32u.dll!NtUserSetFocus Unknown jengined.dll!JWinLayer::SetActive Line 6982 C++ jengined.dll!JWinLayer::IJWindowImp::put_Visible Line 3160 C++ jengined.dll!JDocWindows::ShowAllWindows Line 1193 C++ jengined.dll!JShowAllWindows Line 805 C++ jengined.dll!JDocument::Load Line 971 C++ jengined.dll!JDocument::IJPersistStorageImp::Load Line 1276 C++ jengined.dll!JDocuments::IJDocumentsImp::OpenEx Line 4527 C++ jengined.dll!OpenFile Line 17862 C++ jengined.dll!OnOpenMRUEx Line 11578 C++ jengined.dll!JBuiltInCommand::WakeUp Line 195 C++ jengined.dll!JBuiltInCommand::IJCommandImp::WakeUp Line 129 C++ jengined.dll!JSTACKENTRY::WakeUp<void const *> Line 385 C++ jengined.dll!JApplication::StartCommand<void const *> Line 2387 C++ jengined.dll!JExecuteBuiltInCommand Line 325 C++ jengined.dll!JBuiltInCommandTable::Execute Line 25321 C++ jengined.dll!StartAndExecuteCommand Line 6638 C++ jengined.dll!CommandHandler Line 6910 C++ jengined.dll!JApplication::WindowProc Line 10037 C++ jengined.dll!JApplication::EngineFrameWindowProc Line 8463 C++ user32.dll!UserCallWinProcCheckWow Unknown user32.dll!CallWindowProcW Unknown Microsoft.VisualStudio.Debugger.Runtime.Impl.dll!DetouredCallWindowProcW Unknown mfc140ud.dll!_AfxActivationWndProc Line 478 C++ user32.dll!UserCallWinProcCheckWow Unknown user32.dll!CallWindowProcW Unknown Microsoft.VisualStudio.Debugger.Runtime.Impl.dll!DetouredCallWindowProcW Unknown jengined.dll!JFrameWnd::OnCommand Line 8088 C++ mfc140ud.dll!CWnd::OnWndMsg Line 2113 C++ ToolkitPro2010vc160x64UD.dll!CXTPCommandBarsSiteBase::OnWndMsg Line 208 C++ mfc140ud.dll!CWnd::WindowProc Line 2099 C++ jengined.dll!JFrameWnd::WindowProc Line 15152 C++ mfc140ud.dll!AfxCallWndProc Line 265 C++ mfc140ud.dll!AfxWndProc Line 418 C++ mfc140ud.dll!AfxWndProcBase Line 299 C++ user32.dll!UserCallWinProcCheckWow Unknown user32.dll!CallWindowProcW Unknown Microsoft.VisualStudio.Debugger.Runtime.Impl.dll!DetouredCallWindowProcW Unknown ToolkitPro2010vc160x64UD.dll!CXTPHookManager::HookWndProc Line 449 C++ user32.dll!UserCallWinProcCheckWow Unknown user32.dll!DispatchMessageWorker Unknown jengined.dll!ProcessEventLoopCPP Line 5574 C++ jengined.dll!JProcessEventLoop Line 5699 C++ jengined.dll!JMainEngine::Run Line 2402 C++ jengined.dll!JWinMain Line 300 C++ SEStartupD.dll!JStartupSolidEdgeCommon Line 488 C++ EdgeD.exe!Run_SolidEdge Line 211 C++ EdgeD.exe!CSolidEdgeWinApp::Run Line 45 C++ mfc140ud.dll!AfxWinMain Line 47 C++ EdgeD.exe!wWinMain Line 26 C++ EdgeD.exe!invoke_main Line 123 C++ EdgeD.exe!__scrt_common_main_seh Line 288 C++ EdgeD.exe!__scrt_common_main Line 331 C++ EdgeD.exe!wWinMainCRTStartup Line 17 C++ kernel32.dll!BaseThreadInitThunk Unknown ntdll.dll!RtlUserThreadStart Unknown

Hope I give no trade secrets away :)

RDH
  • 29
  • 4
  • `when (ex.InnerException is Win32Exception)` why do you have this? Also catches go sequentially, so if you want `catch (Win32Exception ex)` to happen first you need to place it first. – Charlieface May 11 '23 at 12:32
  • I did that because adding "catch( Exception ex)" was the first thing I did. It didn't catch it. So then I tried catching the exact exception via "catch( System.ComponentModel.Win32Exception Ex)". Still no catch. Then I found that "when" code on stackoverflow and tried it. Even the code that calls this API has try/finally and it wasn't working either which is why I tried adding code to this simple function. – RDH May 11 '23 at 15:06
  • Then I can only imagine you are catching in the wrong place. `catch (Exception)` always catches everything. – Charlieface May 11 '23 at 15:28
  • Sorry Charlie, I don't think so. Too bad I can't paste in the snipping tool picture. This is a xaml window and a simple call to Show on it. My picture shows the exception and the code point in the debugger as well as the try catch. The message box is "Exception Unhandled" with the mysterious "quota" message that occurs at the Show call. – RDH May 11 '23 at 20:47
  • You are asking me to believe that something which has been in C# since v1 and has always worked now doesn't work? When you use `catch (Exception)` it will always catch any possible exception, except for stackoverflow, outofmemory and accessviolation. But you may want to look at this https://stackoverflow.com/questions/20964360/not-enough-quota-is-available-to-process-this-command-wpf – Charlieface May 11 '23 at 20:49
  • Hi Charlie. Did you see the image I posted? I'm beginning to believe this is a xaml bug. I cannot get a handle until Show is called. The window will be reparented via OS SetParent API. Been doing that with WinForm windows with no issue. With WinForm, no Show is needed to get the handle. I was hoping to avoid the Show until parenting to our handle. Nor can I set the owner (private property). So, the window is created as owned by the desktop. I got this because our European ISVs have been unable to solve the issue. This is .NET WPF in a (classic) desktop app. No .NET app wnd as a parent/owner. – RDH May 11 '23 at 21:04
  • Please show the call stack it might be on another thread – Charlieface May 11 '23 at 21:06
  • So one thing I have noticed when this happens. Though I have a ton of virtual memory available, I have committed a few gigs over the ram I have available and am starting to page fault when the exception occurs. What is this "quota" in reality? There is no clue, even in the message. The code generating the exception is PresentationCore.dll!System.Windows.Interop.HwndTarget.UpdateWindowSettings(bool enableRenderTarget, System.Windows.Media.Composition.DUCE.ChannelSet? channelSet). And I thought MFC CWnd was heavy but the memory CWnd uses is no match for this Window class and the xaml content. – RDH May 11 '23 at 21:16
  • Sounds like you are getting an outofmemory which is an uncatchable error. Can you show the *full* call stack ([edit] your post, and paste text not images) – Charlieface May 11 '23 at 21:19
  • So that's the stack from the Show call up. Had to break it into pieces and have the debugger hide args so I could get it small enough to use in a comment due to the limit of characters. Probably should have edited my original post. Doh! – RDH May 11 '23 at 21:23
  • One other thing. Just in case I called GC.Collect after each window was successfully created just to see if it made a difference. It didn't. – RDH May 11 '23 at 21:25
  • Yes that's what I said, click the [edit] button, and then delete all those comments. Yes looks like it might be coming from another thread. Not sure what to say – Charlieface May 11 '23 at 21:39
  • The exception is on the main thread. – RDH May 12 '23 at 16:56
  • Well .NET can't catch this exception but being a native app SetUnhandledExceptionFilter sure lets me catch it. That's just too late as I want anyone that writes .NET code that gets into our app to trap their own exceptions. – RDH May 12 '23 at 18:10

1 Answers1

0

It turns out this .NET message, at least in this case, cannot be caught. It cannot be ignored in an installed exception handler by our win32 app either. The root cause of our issue was exceeding the message queue limit of 10,000 messages. When calling PostMessage, PostMessage will return FALSE if the limit is encountered. No real harm done, at least no crash or exception, except when some .NET code deteremines a message failed to post. .NET throws the exception and forces the app down. I cannot even return recover from this at the lowest level by returning EXCEPTION_CONTINUE_EXECUTION tell the OS to coninue execution.

RDH
  • 29
  • 4