mgth/LittleBigMouse · error · Exception
No window found
Error message
No window found
What it means
MainWindowManager.Show resolves the view for a view-model through mvvmService.MainContext.GetView<DefaultViewMode> and converts it to a window via AsWindow(). When the view is null or AsWindow() yields null (the MVVM context has no registered view/template for that view-model), a plain Exception('No window found') is thrown instead of silently returning.
Solutions
- Verify the view class for this view-model exists, implements IDefaultViewClass, and is registered with the MVVM context (DataTemplates / locator) before calling Show.
- Ensure the assembly containing the view is loaded and scanned by the mvvmService before Show is invoked.
- Pass the correct view-model instance produced by the app's navigation/service layer, not an ad-hoc instance whose type has no registered view.
- Wrap the call and fall back to creating the DefaultWindow manually if the resolver returns null.
Example fix
// before
_manager.Show(viewModel); // throws 'No window found' if view unregistered
// after
var view = mvvmService.MainContext.GetView<DefaultViewMode>(viewModel, typeof(IDefaultViewClass));
if (view?.AsWindow() is null)
_logger.Warn("No registered view for {Vm}; skipping window show", viewModel.GetType().Name);
else
_manager.Show(viewModel); Defensive patterns
Strategy: try-catch
Validate before calling
// before calling Show
var probe = mvvmService.MainContext.GetView<DefaultViewMode>(viewModel, typeof(IDefaultViewClass));
if (probe?.AsWindow() is null)
throw new InvalidOperationException(
$"No view registered for {viewModel.GetType().Name}; check DataTemplates/locator registration"); Type guard
bool HasRegisteredWindow(object viewModel, IMvvmService mvvm) =>
mvvm.MainContext
.GetView<DefaultViewMode>(viewModel, typeof(IDefaultViewClass))
?.AsWindow() is not null; Try / catch
try { mainWindowManager.Show(viewModel); }
catch (Exception ex) when (ex.Message == "No window found")
{ _logger.Error("View for {Vm} is not registered", viewModel.GetType().Name); /* skip or fall back */ } Prevention
- Register every view/view-model pair in the Avalonia DataTemplates or locator before any Show call.
- Ensure the view assembly is loaded (referenced and scanned) at startup, before plugin windows are requested.
- Keep view classes implementing IDefaultViewClass so GetView + AsWindow can resolve them.
- Smoke-test each navigable view-model's Show path in CI to catch missing registrations early.
When it happens
Trigger: Calling Show(viewModel) when no view is registered for the view-model type under DefaultViewMode/IDefaultViewClass — e.g. the view assembly was not loaded, the view-model was constructed manually without the matching view registration, or AsWindow() cannot convert the resolved view to a Window.
Common situations: A plugin or DI refactor removed/renamed the view registration; launching a UI surface (e.g. main window) before the Avalonia view locator is initialized; asking for a window type whose class does not implement IDefaultViewClass; headless/CI environment where views fail to materialize.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
AI-assisted analysis of mgth/LittleBigMouse@7a42f01d47 (2026-09-16).
Data as JSON: /api/errors/4ab7d38ccfbf30aa.
Report an issue: GitHub.
Appendix: source
Thrown at LittleBigMouse.Ui/LittleBigMouse.Ui.Avalonia/Main/MainWindowManager.cs:67
public void Show(IMainService mainService, Func<Window, Task<bool>> confirmClose)
{
if (_window?.IsLoaded == true)
{
_window.WindowState = WindowState.Normal;
_window.Activate();
return;
}
var viewModel = viewModelLocator();
viewModel.MainService = mainService;
_plugins?.Invoke(viewModel);
var view = mvvmService
.MainContext
.GetView<DefaultViewMode>(viewModel, typeof(IDefaultViewClass));
var window = view?.AsWindow() ?? throw new Exception("No window found");
// AsWindow() creates a bare DefaultWindow with no size: restore the last
// session's geometry (or a sensible default) and save it back on close.
MainWindowGeometry.Attach(window);
var subscriptions = new CompositeDisposable();
var closeConfirmed = false;
void OnClosed(object? sender, EventArgs e)
{
_window = null;
ReleaseWindowSubscriptions();
}
async void OnClosing(object? sender, WindowClosingEventArgs e)
{
if (closeConfirmed || sender is not Window closing) return;
View on GitHub (pinned to 7a42f01d47)