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 ...
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 :)