{"record":{"id":"4ab7d38ccfbf30aa","repo":"mgth/LittleBigMouse","slug":"no-window-found","errorCode":null,"errorMessage":"No window found","messagePattern":"No window found","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"LittleBigMouse.Ui/LittleBigMouse.Ui.Avalonia/Main/MainWindowManager.cs","lineNumber":67,"sourceCode":"    public void Show(IMainService mainService, Func<Window, Task<bool>> confirmClose)\n    {\n        if (_window?.IsLoaded == true)\n        {\n            _window.WindowState = WindowState.Normal;\n            _window.Activate();\n            return;\n        }\n\n        var viewModel = viewModelLocator();\n        viewModel.MainService = mainService;\n\n        _plugins?.Invoke(viewModel);\n\n        var view = mvvmService\n            .MainContext\n            .GetView<DefaultViewMode>(viewModel, typeof(IDefaultViewClass));\n\n        var window = view?.AsWindow() ?? throw new Exception(\"No window found\");\n\n        // AsWindow() creates a bare DefaultWindow with no size: restore the last\n        // session's geometry (or a sensible default) and save it back on close.\n        MainWindowGeometry.Attach(window);\n\n        var subscriptions = new CompositeDisposable();\n        var closeConfirmed = false;\n\n        void OnClosed(object? sender, EventArgs e)\n        {\n            _window = null;\n            ReleaseWindowSubscriptions();\n        }\n\n        async void OnClosing(object? sender, WindowClosingEventArgs e)\n        {\n            if (closeConfirmed || sender is not Window closing) return;\n","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/mgth/LittleBigMouse/blob/7a42f01d47d99d223b8ee33ba4019af82adf1c48/LittleBigMouse.Ui/LittleBigMouse.Ui.Avalonia/Main/MainWindowManager.cs#L49-L85","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n_manager.Show(viewModel); // throws 'No window found' if view unregistered\n// after\nvar view = mvvmService.MainContext.GetView<DefaultViewMode>(viewModel, typeof(IDefaultViewClass));\nif (view?.AsWindow() is null)\n    _logger.Warn(\"No registered view for {Vm}; skipping window show\", viewModel.GetType().Name);\nelse\n    _manager.Show(viewModel);","handlingStrategy":"try-catch","validationCode":"// before calling Show\nvar probe = mvvmService.MainContext.GetView<DefaultViewMode>(viewModel, typeof(IDefaultViewClass));\nif (probe?.AsWindow() is null)\n    throw new InvalidOperationException(\n        $\"No view registered for {viewModel.GetType().Name}; check DataTemplates/locator registration\");","typeGuard":"bool HasRegisteredWindow(object viewModel, IMvvmService mvvm) =>\n    mvvm.MainContext\n        .GetView<DefaultViewMode>(viewModel, typeof(IDefaultViewClass))\n        ?.AsWindow() is not null;","tryCatchPattern":"try { mainWindowManager.Show(viewModel); }\ncatch (Exception ex) when (ex.Message == \"No window found\")\n{ _logger.Error(\"View for {Vm} is not registered\", viewModel.GetType().Name); /* skip or fall back */ }","preventionTips":["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."],"tags":["avalonia","mvvm","window-management","view-resolution"],"backgroundTag":"entity-not-found","analyzedSha":"7a42f01d47d99d223b8ee33ba4019af82adf1c48","analyzedAt":"2026-09-16T00:35:00.514Z","contentChangedAt":"2026-09-16T00:35:00.514Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}