{"record":{"id":"db4eca292941fc7c","repo":"tui-cs/Terminal.Gui","slug":"driver-not-initialized-call-init-first","errorCode":null,"errorMessage":"Driver not initialized. Call Init() first.","messagePattern":"Driver not initialized\\. Call Init\\(\\) first\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/App/ApplicationImpl.cs","lineNumber":196,"sourceCode":"\n    /// <inheritdoc/>\n    public IClipboard? Clipboard { get => Driver?.Clipboard; set => Driver?.Clipboard = value; }\n\n    #endregion Screen and Driver\n\n    #region Input (Mouse/Keyboard)\n\n    /// <inheritdoc/>\n    public IInputInjector GetInputInjector ()\n    {\n        if (_inputInjector is { })\n        {\n            return _inputInjector;\n        }\n\n        if (Driver is null)\n        {\n            throw new InvalidOperationException (\"Driver not initialized. Call Init() first.\");\n        }\n\n        IInputProcessor processor = Driver.GetInputProcessor ();\n        _inputInjector = new InputInjector (processor, _timeProvider);\n\n        return _inputInjector;\n    }\n\n    private IKeyboard? _keyboard;\n\n    /// <inheritdoc/>\n    public IKeyboard Keyboard\n    {\n        get\n        {\n            _keyboard ??= new ApplicationKeyboard { App = this };\n\n            return _keyboard;","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/App/ApplicationImpl.cs#L178-L214","documentation":"Thrown by ApplicationImpl.GetInputInjector when Driver is null. The InputInjector wraps the driver's IInputProcessor to inject keys/mouse events for testing; without an initialized driver there is no input processor to wrap. The driver is set during Init, so this indicates GetInputInjector was called before Init completed.","triggerScenarios":"Calling app.GetInputInjector() before app.Init(); calling it in a View constructor that runs during application setup before the driver is assigned; test code that requests the injector without a live driver.","commonSituations":"UI testing harnesses that grab the injector too early; component initialization order issues; refactoring that moved injector acquisition before Init.","solutions":["Call GetInputInjector only after Init has completed and Driver is non-null.","Guard with 'if (app.Driver is not null) var injector = app.GetInputInjector();'.","Acquire the injector inside the Run loop or after the InitializedChanged event."],"exampleFix":"// before\nvar injector = app.GetInputInjector (); // Driver null\n\n// after\nif (app.Driver is not null)\n{\n    var injector = app.GetInputInjector ();\n}","handlingStrategy":"validation","validationCode":"if (app.Driver is not null)\n{\n    var injector = app.GetInputInjector ();\n}","typeGuard":"static bool HasDriver (IApplication app) => app.Driver is not null;","tryCatchPattern":null,"preventionTips":["Call GetInputInjector only after Init completes.","Guard with app.Driver is not null.","Acquire the injector inside the Run loop or after InitializedChanged."],"tags":["input","testing","driver","initialization"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}