Ich habe eine eigenständige Software, die in Maui entwickelt wurde. Es ist ein ziemlich komplexes Ergebnis der Entwicklung von vielen Jahren und nicht nur ich als Entwickler. Dies ist die Methode. < /p>
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var exception = e.ExceptionObject as Exception;
ErrorHandler.LogError(exception, $"OnUnhandledException caught unhandled exception {exception.InnerException}");
ShowErrorAlert($"An unexpected error occurred. The error has been logged. {exception.InnerException}");
}
private void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
ErrorHandler.LogError(e.Exception, "OnUnobservedTaskException caught unhandled exception");
e.SetObserved(); // Prevent the application from crashing
ShowErrorAlert($"An unexpected error occurred. The error has been logged. {e.Exception}");
}
< /code>
Der Fehlerhandler füllt die Protokolle einfach in eine Textdatei. public static void LogError(Exception ex, string context)
{
Log.Error(ex, "An error occurred in {Context}", context);
}
< /code>
Hier ist das, was ich im Protokoll finde < /p>
2025-09-05 14:16:54.927 +00:00 [ERR] An error occurred in OnUnhandledException caught unhandled exception
System.Runtime.InteropServices.COMException (0x8001010E)
at WinRT.ExceptionHelpers.g__Throw|38_0(Int32 hr)
at Microsoft.UI.Xaml.Controls.ContentDialog._IContentDialogFactory.CreateInstance(Object baseInterface, IntPtr& innerInterface)
at Microsoft.UI.Xaml.Controls.ContentDialog..ctor()
at Microsoft.Maui.Controls.Platform.AlertDialog..ctor()
at Microsoft.Maui.Controls.Platform.AlertManager.AlertRequestHelper.OnAlertRequested(Page sender, AlertArguments arguments)
at System.Threading.Tasks.Task.c.b__128_1(Object state)
at System.Threading.QueueUserWorkItemCallback.Execute()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
2025-09-05 14:17:08.378 +00:00 [ERR] An error occurred in OnUnhandledException caught unhandled exception
System.Runtime.InteropServices.COMException (0x8001010E)
at WinRT.ExceptionHelpers.g__Throw|38_0(Int32 hr)
at Microsoft.UI.Xaml.Controls.ContentDialog._IContentDialogFactory.CreateInstance(Object baseInterface, IntPtr& innerInterface)
at Microsoft.UI.Xaml.Controls.ContentDialog..ctor()
at Microsoft.Maui.Controls.Platform.AlertDialog..ctor()
at Microsoft.Maui.Controls.Platform.AlertManager.AlertRequestHelper.OnAlertRequested(Page sender, AlertArguments arguments)
at System.Threading.Tasks.Task.c.b__128_1(Object state)
at System.Threading.QueueUserWorkItemCallback.Execute()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
< /code>
Jetzt, da die Anwendung nicht auf Visual Studio ausgeführt wird, kann ich nicht mit dem Debugger testen, und ich bin mir nicht sicher, welche Strategie ich folgen kann, um zu verstehen, was die Wurzel dieser Ausnahme ist. Bisher hatte ich dieses Problem mit XAML -Kompilierungsfehlern, die normalerweise nicht aufgenommen werden, und landen in unberechtigten Ausnahmen. Selbst mit Visual Studio waren diese schwierig zu debuggen, da nur wenige Informationen auf die endgültige Ausnahme -Metadaten bringen. (was hier nicht viel hilft)
Unsicher, wie man uneingeschränkte Ausnahme Maui debugg ⇐ C#
-
- Similar Topics
- Replies
- Views
- Last post
Mobile version