Flow-Launcher/Flow.Launcher · error · InvalidOperationException

Failed to deserialize double pinyin table: result is null

Error message

Failed to deserialize double pinyin table: result is null

What it means

Thrown as InvalidOperationException when JsonSerializer.Deserialize of the double-pinyin table JSON returns null — which for a Dictionary target happens only when the JSON stream contains a literal null token (not an empty object). The table is loaded from Resources/double_pinyin.json at the app base directory. LoadDoublePinyinTable does NOT catch this specific exception, so it propagates.

Source

Thrown at Flow.Launcher.Infrastructure/PinyinAlphabet.cs:56

                        if (_settings.UseDoublePinyin)
                        {
                            Reload();
                        }
                        break;
                }
            };
        }

        public void Reload()
        {
            LoadDoublePinyinTable();
            _pinyinCache.Clear();
        }

        private void CreateDoublePinyinTableFromStream(Stream jsonStream)
        {
            var table = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(jsonStream) ??
                throw new InvalidOperationException("Failed to deserialize double pinyin table: result is null");

            var schemaKey = _settings.DoublePinyinSchema.ToString();
            if (!table.TryGetValue(schemaKey, out var schemaDict))
            {
                throw new ArgumentException($"DoublePinyinSchema '{schemaKey}' is invalid or double pinyin table is broken.");
            }

            currentDoublePinyinTable = new ReadOnlyDictionary<string, string>(schemaDict);
        }

        private void LoadDoublePinyinTable()
        {
            if (!_settings.UseDoublePinyin)
            {
                currentDoublePinyinTable = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>());
                return;
            }

View on GitHub (pinned to 7fc63b07bb)

Solutions

  1. Restore Resources/double_pinyin.json from a known-good Flow Launcher install or the source repo.
  2. Open the file and confirm it is a JSON object like {"SchemaName": {"key":"value"}}, not the literal null.
  3. If customizing, validate the JSON parses to a non-null Dictionary before saving.
  4. Reinstall Flow Launcher to restore shipped resources.

Example fix

// before
var table = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string,string>>>(jsonStream)
    ?? throw new InvalidOperationException("Failed to deserialize double pinyin table: result is null");

// after — treat null as empty and warn, so the feature degrades instead of crashing
var table = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string,string>>>(jsonStream)
    ?? new Dictionary<string, Dictionary<string,string>>();
if (table.Count == 0)
    Log.Warn(nameof(PinyinAlphabet), "Double pinyin table was null/empty; feature disabled");
Defensive patterns

Strategy: validation

Validate before calling

var raw = File.ReadAllText(tablePath);
if (string.IsNullOrWhiteSpace(raw) || raw.Trim() == "null")
{ Log.Warn(...); currentDoublePinyinTable = Empty; return; }

Type guard

null

Try / catch

try { CreateDoublePinyinTableFromStream(fs); }
catch (InvalidOperationException ex) when (ex.Message.Contains("result is null"))
{ Log.Exception(...); currentDoublePinyinTable = Empty; }

Prevention

When it happens

Trigger: The double_pinyin.json file content is literally the text 'null' (a JSON null token); the stream is positioned such that the first token is null; a manual/automated edit replaced the table contents with null. A missing or malformed-but-non-null file would throw JsonException instead.

Common situations: A user or tool overwrote Resources/double_pinyin.json with 'null' while experimenting; a build/packaging step corrupted the resource; a partial file write left only the token 'null'; the resource file was replaced by a placeholder during a failed update.

Related errors


AI-assisted analysis of Flow-Launcher/Flow.Launcher@7fc63b07bb (2026-08-13). Data as JSON: /api/errors/2cdb343f88af4e0c. Report an issue: GitHub.