Hi John,
Great question. In Avalonia, calling Window.ShowDialog without an owner will throw an exception because a dialog must have an owner. Without an owner, you can show a window but it would not be modal. We currently only support ShowDialog and require an owner because Avalonia requires it.
Note that attempting to show a User Prompt on non-desktop platforms, like a browser using WASM, would not be possible without an owner to host the overlay that displays the prompt.
The scenario you're describing is pretty much the only scenario I can think of where you would not have a window available to be the owner. There are a few reasons why this may not work as expected even if we supported Show (without an owner):
- Any fatal exception thrown during application startup will cause the application to terminate, and any non-blocking calls to show a window at this time would likely see the running process terminated before the window could even be shown.
- If application startup has failed, that likely means application resources are also not properly initialized and the User Prompt would not have the styles and templates necessary to properly display information.
- If the main window fails to load, I honestly don't even know if Avalonia would support loading/showing a separate window.
In that specific scenario, I think logging exceptions may be the most consistent way to ensure startup exceptions are captured. If a non-fatal exception is detected during application startup, the exception details could be cached in a global variable, allow startup to continue, and then display any cached exceptions after the main window loads.
If you wanted to experiment, you could try hosting our UserPromptControl inside a standard Window and show it without an owner using code like this:
try {
// ...
}
catch (Exception ex) {
// Build the UserPromptControl configured for the exception
var userPromptControl = UserPromptBuilder.Configure()
.ForException(ex)
.BuildWithoutShowing();
// Show the control in your own window
var window = new Window() {
Content = userPromptControl
};
window.Show();
}