{"record":{"id":"b808b12b83971f17","repo":"ElectronNET/Electron.NET","slug":"invalid-value-for-titlebaroverlay-expected-boolean-or-an","errorCode":null,"errorMessage":"Invalid value for TitleBarOverlay. Expected boolean or an object.","messagePattern":"Invalid value for TitleBarOverlay\\. Expected boolean or an object\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/ElectronNET.API/Converter/TitleBarOverlayConverter.cs","lineNumber":24,"sourceCode":"\nnamespace ElectronNET.Converter;\n\npublic class TitleBarOverlayConverter : JsonConverter<TitleBarOverlay>\n{\n    public override TitleBarOverlay Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n    {\n        if (reader.TokenType == JsonTokenType.True || reader.TokenType == JsonTokenType.False)\n        {\n            return (bool)reader.GetBoolean();\n        }\n        else if (reader.TokenType == JsonTokenType.StartObject)\n        {\n            using var doc = JsonDocument.ParseValue(ref reader);\n            return doc.RootElement.Deserialize<TitleBarOverlay>(ElectronJson.Options);\n        }\n        else\n        {\n            throw new JsonException(\"Invalid value for TitleBarOverlay. Expected boolean or an object.\");\n        }\n    }\n\n    public override void Write(Utf8JsonWriter writer, TitleBarOverlay value, JsonSerializerOptions options)\n    {\n        if (value is null)\n        {\n            return;\n        }\n\n        var @bool = (bool?)value;\n        if (@bool.HasValue)\n        {\n            writer.WriteBooleanValue(@bool.Value);\n        }\n        else\n        {\n            JsonSerializer.Serialize(writer, value, ElectronJson.Options);","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/ElectronNET/Electron.NET/blob/87cc6f98b6a9c5968d7846c0e775ea713bd0d7b2/src/ElectronNET.API/Converter/TitleBarOverlayConverter.cs#L6-L42","documentation":"TitleBarOverlayConverter.Read only accepts a JSON boolean or object for TitleBarOverlay values; anything else (string, number, array, null token variants it does not handle) triggers this JsonException. The converter exists because the Windows titleBarOverlay option can be either a boolean flag or an options object.","triggerScenarios":"Calling Electron.WindowManager or BrowserWindow APIs (e.g. setTitleBarOverlay, window options) with a titleBarOverlay value serialized as a string like \"true\" or \"overlay\", or any non-boolean/non-object JSON token.","commonSituations":"Passing titleBarOverlay options from client-side JS as a JSON string instead of a real object/boolean; older bridge clients sending wrong types; hand-written config JSON quoting the value.","solutions":["Send titleBarOverlay as a real boolean (true/false) or a plain object, not a string","Remove quotes around the value in the calling code or JSON payload","If using custom JS, ensure JSON.parse is applied before sending to the bridge"],"exampleFix":"// before\nwin.setTitleBarOverlay(\"true\");\n// after\nwin.setTitleBarOverlay(true);\n// or\nwin.setTitleBarOverlay({ color: '#000000', symbolColor: '#ffffff' });","handlingStrategy":"validation","validationCode":"// client-side: ensure titleBarOverlay is bool or object before sending\nconst ok = typeof titleBarOverlay === 'boolean' ||\n           (titleBarOverlay !== null && typeof titleBarOverlay === 'object' && !Array.isArray(titleBarOverlay));\nif (!ok) throw new TypeError('titleBarOverlay must be a boolean or object');","typeGuard":"static bool IsValidTitleBarOverlay(JsonElement e) =>\n    e.ValueKind is JsonValueKind.True or JsonValueKind.False or JsonValueKind.Object;","tryCatchPattern":"try\n{\n    var overlay = doc.RootElement.Deserialize<TitleBarOverlay>(ElectronJson.Options);\n}\ncatch (JsonException ex)\n{\n    logger.LogWarning(ex, \"Invalid titleBarOverlay value in payload\");\n}","preventionTips":["Pass titleBarOverlay as a native JS boolean/object, never a quoted string","Validate payloads with JSON.parse before bridging","Keep Electron host files and .NET package versions aligned"],"tags":["json","deserialization","electron","titlebar"],"backgroundTag":"invalid-argument-value","analyzedSha":"87cc6f98b6a9c5968d7846c0e775ea713bd0d7b2","analyzedAt":"2026-09-14T03:09:47.608Z","contentChangedAt":"2026-09-14T03:09:47.608Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}