microsoft/aspire · error · InvalidOperationException

Chromium profile metadata in

Error message

Chromium profile metadata in '{0}' is invalid while resolving browser profile '{1}'.

What it means

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.

Solutions

  1. Restore or regenerate the Local State file (launch Chrome fresh, or restore from backup).
  2. Re-copy the user data directory completely from a healthy source.
  3. Specify the profile by its stable directory name (e.g., 'Default', 'Profile 1') and avoid metadata-based resolution if the file is unusable.
  4. Catch this exception and prompt the user to pick the profile directory manually.

Example fix

// before
var dir = resolver.ResolveProfileDirectory(userData, "Work");
// after
try
{
    var dir = resolver.ResolveProfileDirectory(userData, "Work");
}
catch (InvalidOperationException ex)
{
    // metadata corrupt — fall back to known directory name
    var dir = Path.Combine(userData, "Default");
}
Defensive patterns

Strategy: fallback

Validate before calling

// Cheap pre-check: metadata must at least be non-empty JSON-ish
var metaPath = Path.Combine(userDataDirectory, "Local State");
bool looksValid = File.Exists(metaPath) && new FileInfo(metaPath).Length > 2;

Try / catch

try
{
    var dir = resolver.ResolveProfileDirectory(userData, profile);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("is invalid"))
{
    // metadata corrupt: fall back to well-known directory names
    var fallback = Path.Combine(userData, "Default");
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/b12e9dc4f9ed9062. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Browsers/ChromiumBrowserResolver.cs:106

                {
                    return profileDirectory;
                }
            }
            catch (IOException ex)
            {
                throw new InvalidOperationException(
                    string.Format(CultureInfo.CurrentCulture, BrowserMessageStrings.BrowserLogsUnableToReadProfileMetadata, localStatePath, profile),
                    ex);
            }
            catch (UnauthorizedAccessException ex)
            {
                throw new InvalidOperationException(
                    string.Format(CultureInfo.CurrentCulture, BrowserMessageStrings.BrowserLogsUnableToReadProfileMetadata, localStatePath, profile),
                    ex);
            }
            catch (JsonException ex)
            {
                throw new InvalidOperationException(
                    string.Format(CultureInfo.CurrentCulture, BrowserMessageStrings.BrowserLogsInvalidProfileMetadata, localStatePath, profile),
                    ex);
            }
        }

        throw new InvalidOperationException(
            string.Format(CultureInfo.CurrentCulture, BrowserMessageStrings.BrowserLogsProfileNotFound, profile, userDataDirectory));
    }

    /// <summary>
    /// Resolves a profile directory from Chromium's parsed Local State metadata.
    /// </summary>
    internal static string? TryResolveProfileDirectory(JsonElement localStateRoot, string userDataDirectory, string profile)
    {
        ArgumentException.ThrowIfNullOrWhiteSpace(userDataDirectory);
        ArgumentException.ThrowIfNullOrWhiteSpace(profile);

        if (!localStateRoot.TryGetProperty("profile", out var profileElement) ||

View on GitHub (pinned to 25830f84bd)