builtbybel/FlyOOBE · error · ArgumentNullException
LoggerControlView cannot be null.
Error message
LoggerControlView cannot be null.
What it means
The static Logger.SetLoggerControl method wires the logging system to a LoggerControlView UI control so buffered log messages can be flushed to the screen. Because the static logger has no other render target, passing null is rejected with ArgumentNullException carrying the message 'LoggerControlView cannot be null.'
Solutions
- Create the LoggerControlView before calling SetLoggerControl and pass the live instance
- Move the SetLoggerControl call to the view's Load/Shown event where the control exists
- Null-check or verify the control lookup returned a real instance before calling SetLoggerControl
- If the UI is intentionally absent (headless), add an overload or flag that buffers logs without a control instead of passing null
Example fix
// before
Logger.SetLoggerControl(loggerControlView); // loggerControlView is null here
// after
if (loggerControlView != null)
{
Logger.SetLoggerControl(loggerControlView);
}
else
{
Logger.SetLoggerControl(new LoggerControlView());
} Defensive patterns
Strategy: type-guard
Validate before calling
if (loggerControl == null)
{
loggerControl = new LoggerControlView();
}
Logger.SetLoggerControl(loggerControl); Type guard
bool HasLoggerControl() => loggerControlView != null && !loggerControlView.IsDisposed;
Try / catch
try
{
Logger.SetLoggerControl(loggerControlView);
}
catch (ArgumentNullException ex) when (ex.ParamName == "loggerControl")
{
// keep logs buffered; attach the control later in Form.Load
Logger.SetLoggerControl(new LoggerControlView());
} Prevention
- Wire SetLoggerControl in Form.Load/Shown, not the constructor
- Null-check designer-generated control fields before use
- Never pass null to satisfy the API — buffer logs instead
- Verify control names after designer refactors/renames
When it happens
Trigger: Calling `Logger.SetLoggerControl(null)` — e.g. the control is created lazily after the view loads, a FindControl/lookup returned null, or the control variable was never assigned before wiring the logger.
Common situations: Calling SetLoggerControl in a form constructor before LoggerControlView is instantiated; a renamed or removed control making a designer field null; calling it from a different page/view where the control does not exist; DI resolution returning null.
Related errors
AI-assisted analysis of builtbybel/FlyOOBE@ed093a784d (2026-09-14).
Data as JSON: /api/errors/413bc6df1b053ee1.
Report an issue: GitHub.
Appendix: source
Thrown at Flyoobe/Helper/Logger.cs:34
// The active log view control where log messages are displayed
private static LoggerControlView loggerControlInstance;
// Temporary storage for logs before the UI is ready (e.g., during app startup)
private static readonly List<(string Message, Color Color)> logBuffer = new List<(string, Color)>();
// Reference to the view navigation system so we can switch to the log view on demand
private static ViewNavigator navigator;
// Optional: name of the current log "section" (helps group logs visually)
private static string currentSection;
/// <summary>
/// Sets the LoggerControlView instance dynamically.
/// </summary>
public static void SetLoggerControl(LoggerControlView loggerControl)
{
if (loggerControl == null)
throw new ArgumentNullException(nameof(loggerControl), "LoggerControlView cannot be null.");
loggerControlInstance = loggerControl;
// Flush any buffered logs to the UI
foreach (var log in logBuffer)
{
loggerControlInstance.AddLog(log.Message, log.Color);
}
// logBuffer.Clear(); // keep buffer if history retention needed
}
/// <summary>
/// Logs a message using the given LogLevel.
/// Each level has its own color.
/// </summary>
public static void Log(string message, LogLevel level = LogLevel.Info)
{View on GitHub (pinned to ed093a784d)