{"record":{"id":"b12e9dc4f9ed9062","repo":"microsoft/aspire","slug":"chromium-profile-metadata-in-0-is-invalid-while-resolving","errorCode":null,"errorMessage":"Chromium profile metadata in '{0}' is invalid while resolving browser profile '{1}'.","messagePattern":"Chromium profile metadata in '(.+?)' is invalid while resolving browser profile '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Browsers/ChromiumBrowserResolver.cs","lineNumber":106,"sourceCode":"                {\n                    return profileDirectory;\n                }\n            }\n            catch (IOException ex)\n            {\n                throw new InvalidOperationException(\n                    string.Format(CultureInfo.CurrentCulture, BrowserMessageStrings.BrowserLogsUnableToReadProfileMetadata, localStatePath, profile),\n                    ex);\n            }\n            catch (UnauthorizedAccessException ex)\n            {\n                throw new InvalidOperationException(\n                    string.Format(CultureInfo.CurrentCulture, BrowserMessageStrings.BrowserLogsUnableToReadProfileMetadata, localStatePath, profile),\n                    ex);\n            }\n            catch (JsonException ex)\n            {\n                throw new InvalidOperationException(\n                    string.Format(CultureInfo.CurrentCulture, BrowserMessageStrings.BrowserLogsInvalidProfileMetadata, localStatePath, profile),\n                    ex);\n            }\n        }\n\n        throw new InvalidOperationException(\n            string.Format(CultureInfo.CurrentCulture, BrowserMessageStrings.BrowserLogsProfileNotFound, profile, userDataDirectory));\n    }\n\n    /// <summary>\n    /// Resolves a profile directory from Chromium's parsed Local State metadata.\n    /// </summary>\n    internal static string? TryResolveProfileDirectory(JsonElement localStateRoot, string userDataDirectory, string profile)\n    {\n        ArgumentException.ThrowIfNullOrWhiteSpace(userDataDirectory);\n        ArgumentException.ThrowIfNullOrWhiteSpace(profile);\n\n        if (!localStateRoot.TryGetProperty(\"profile\", out var profileElement) ||","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Browsers/ChromiumBrowserResolver.cs#L88-L124","documentation":"When the 'Local State' file is readable but its JSON cannot be deserialized (JsonException), ResolveProfileDirectory wraps it in this InvalidOperationException declaring the metadata invalid. Chromium's metadata exists but is corrupt, empty, or not in the expected schema, so profile names cannot be trusted.","triggerScenarios":"ResolveProfileDirectory reads and parses <userDataDirectory>/Local State and System.Text.Json throws JsonException — truncated file, corrupted JSON, empty file, or unexpected schema from a very old/new Chromium version.","commonSituations":"Chrome crashed mid-write leaving a truncated Local State; hand-edited metadata; partially synced/copied profile where the file was cut off; third-party tools rewriting the file.","solutions":["Restore or regenerate the Local State file (launch Chrome fresh, or restore from backup).","Re-copy the user data directory completely from a healthy source.","Specify the profile by its stable directory name (e.g., 'Default', 'Profile 1') and avoid metadata-based resolution if the file is unusable.","Catch this exception and prompt the user to pick the profile directory manually."],"exampleFix":"// before\nvar dir = resolver.ResolveProfileDirectory(userData, \"Work\");\n// after\ntry\n{\n    var dir = resolver.ResolveProfileDirectory(userData, \"Work\");\n}\ncatch (InvalidOperationException ex)\n{\n    // metadata corrupt — fall back to known directory name\n    var dir = Path.Combine(userData, \"Default\");\n}","handlingStrategy":"fallback","validationCode":"// Cheap pre-check: metadata must at least be non-empty JSON-ish\nvar metaPath = Path.Combine(userDataDirectory, \"Local State\");\nbool looksValid = File.Exists(metaPath) && new FileInfo(metaPath).Length > 2;","typeGuard":null,"tryCatchPattern":"try\n{\n    var dir = resolver.ResolveProfileDirectory(userData, profile);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"is invalid\"))\n{\n    // metadata corrupt: fall back to well-known directory names\n    var fallback = Path.Combine(userData, \"Default\");\n}","preventionTips":["Keep backups of the Local State file when copying profiles.","Copy profiles while the browser is closed to avoid truncated writes.","Prefer resolving by stable directory name when metadata is known-bad."],"tags":["browser","chromium","json","corrupt-metadata"],"backgroundTag":"json-parse-error","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}