tui-cs/Terminal.Gui · error · InvalidOperationException
Driver not initialized. Call Init() first.
Error message
Driver not initialized. Call Init() first.
What it means
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.
Source
Thrown at Terminal.Gui/App/ApplicationImpl.cs:196
/// <inheritdoc/>
public IClipboard? Clipboard { get => Driver?.Clipboard; set => Driver?.Clipboard = value; }
#endregion Screen and Driver
#region Input (Mouse/Keyboard)
/// <inheritdoc/>
public IInputInjector GetInputInjector ()
{
if (_inputInjector is { })
{
return _inputInjector;
}
if (Driver is null)
{
throw new InvalidOperationException ("Driver not initialized. Call Init() first.");
}
IInputProcessor processor = Driver.GetInputProcessor ();
_inputInjector = new InputInjector (processor, _timeProvider);
return _inputInjector;
}
private IKeyboard? _keyboard;
/// <inheritdoc/>
public IKeyboard Keyboard
{
get
{
_keyboard ??= new ApplicationKeyboard { App = this };
return _keyboard;View on GitHub (pinned to 2e47b11478)
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.
Example fix
// before
var injector = app.GetInputInjector (); // Driver null
// after
if (app.Driver is not null)
{
var injector = app.GetInputInjector ();
} Defensive patterns
Strategy: validation
Validate before calling
if (app.Driver is not null)
{
var injector = app.GetInputInjector ();
} Type guard
static bool HasDriver (IApplication app) => app.Driver is not null;
Prevention
- Call GetInputInjector only after Init completes.
- Guard with app.Driver is not null.
- Acquire the injector inside the Run loop or after InitializedChanged.
When it happens
Trigger: 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.
Common situations: UI testing harnesses that grab the injector too early; component initialization order issues; refactoring that moved injector acquisition before Init.
Related errors
- Failed to get input console mode, error code: {GetLastError(
- Failed to set input console mode, error code: {GetLastError(
- Driver '{driverName}' is not registered in DriverRegistry.
- Failed to set screenBuffer console mode, error code: {Marsha
- Failed to get output console mode, error code: {GetLastError
AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13).
Data as JSON: /api/errors/db4eca292941fc7c.
Report an issue: GitHub.