{"record":{"id":"413bc6df1b053ee1","repo":"builtbybel/FlyOOBE","slug":"loggercontrolview-cannot-be-null","errorCode":null,"errorMessage":"LoggerControlView cannot be null.","messagePattern":"LoggerControlView cannot be null\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Flyoobe/Helper/Logger.cs","lineNumber":34,"sourceCode":"        // The active log view control where log messages are displayed\n        private static LoggerControlView loggerControlInstance;\n\n        // Temporary storage for logs before the UI is ready (e.g., during app startup)\n        private static readonly List<(string Message, Color Color)> logBuffer = new List<(string, Color)>();\n\n        // Reference to the view navigation system so we can switch to the log view on demand\n        private static ViewNavigator navigator;\n\n        // Optional: name of the current log \"section\" (helps group logs visually)\n        private static string currentSection;\n\n        /// <summary>\n        /// Sets the LoggerControlView instance dynamically.\n        /// </summary>\n        public static void SetLoggerControl(LoggerControlView loggerControl)\n        {\n            if (loggerControl == null)\n                throw new ArgumentNullException(nameof(loggerControl), \"LoggerControlView cannot be null.\");\n\n            loggerControlInstance = loggerControl;\n\n            // Flush any buffered logs to the UI\n            foreach (var log in logBuffer)\n            {\n                loggerControlInstance.AddLog(log.Message, log.Color);\n            }\n\n            // logBuffer.Clear(); // keep buffer if history retention needed\n        }\n\n        /// <summary>\n        /// Logs a message using the given LogLevel.\n        /// Each level has its own color.\n        /// </summary>\n        public static void Log(string message, LogLevel level = LogLevel.Info)\n        {","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/builtbybel/FlyOOBE/blob/ed093a784df51b19e989395f2ed6443ca1f335dd/Flyoobe/Helper/Logger.cs#L16-L52","documentation":"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.'","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nLogger.SetLoggerControl(loggerControlView); // loggerControlView is null here\n// after\nif (loggerControlView != null)\n{\n    Logger.SetLoggerControl(loggerControlView);\n}\nelse\n{\n    Logger.SetLoggerControl(new LoggerControlView());\n}","handlingStrategy":"type-guard","validationCode":"if (loggerControl == null)\n{\n    loggerControl = new LoggerControlView();\n}\nLogger.SetLoggerControl(loggerControl);","typeGuard":"bool HasLoggerControl() => loggerControlView != null && !loggerControlView.IsDisposed;","tryCatchPattern":"try\n{\n    Logger.SetLoggerControl(loggerControlView);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"loggerControl\")\n{\n    // keep logs buffered; attach the control later in Form.Load\n    Logger.SetLoggerControl(new LoggerControlView());\n}","preventionTips":["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"],"tags":["csharp","winforms","argumentnull","logging","static-logger"],"backgroundTag":"null-argument","analyzedSha":"ed093a784df51b19e989395f2ed6443ca1f335dd","analyzedAt":"2026-09-14T12:05:30.440Z","contentChangedAt":"2026-09-14T12:05:30.440Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}