microsoft/aspire · error · InvalidOperationException

Tracked browser protocol response id was not an integer.

Error message

Tracked browser protocol response id was not an integer.

What it means

In a CDP response frame, the "id" property must be an integer correlating the response with its command. If the parser sees an "id" property whose value is not an integer (string, null, object, etc.), it throws this InvalidOperationException. CDP replies always use numeric ids, so a non-numeric id means a non-conforming or corrupted frame.

Solutions

  1. Inspect the frame with DescribeFrame to see the id value's actual type
  2. Ensure the browser is a standard Chromium build not wrapped by a proxy rewriting JSON
  3. Check any middleware that forwards CDP frames preserves numeric id types
  4. Skip or log non-conforming frames via try-catch instead of crashing

Example fix

// before
var header = BrowserLogsCdpProtocol.ParseMessageHeader(frame); // throws on "id":"12"
// after
try
{
    var header = BrowserLogsCdpProtocol.ParseMessageHeader(frame);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("id was not an integer"))
{
    logger.LogWarning("Non-standard CDP frame skipped: {Frame}", BrowserLogsCdpProtocol.DescribeFrame(frame));
}
Defensive patterns

Strategy: validation

Validate before calling

// sanity check: CDP ids are integers; reject obviously wrong payloads early
// no public pre-parse hook exists; validate at the source (proxy/browser config)

Try / catch

try
{
    var header = BrowserLogsCdpProtocol.ParseMessageHeader(frame);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("id was not an integer"))
{
    logger.LogWarning("CDP frame with non-integer id skipped");
}

Prevention

When it happens

Trigger: ParseMessageHeader reads property name "id" and Utf8JsonReader.TryGetInt64 fails - the value is e.g. "id": "7" (string), null, or an object instead of a JSON number.

Common situations: A wrapper/proxy rewrites CDP frames and serializes ids as strings, a custom automation tool sends non-standard frames, or a corrupted byte stream changes the value's type.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Browsers/BrowserLogsCdpProtocol.cs:97

            }

            if (reader.TokenType != JsonTokenType.PropertyName)
            {
                throw new InvalidOperationException("Tracked browser protocol frame was malformed.");
            }

            var propertyName = reader.GetString();
            if (!reader.Read())
            {
                throw new InvalidOperationException("Tracked browser protocol frame ended unexpectedly.");
            }

            switch (propertyName)
            {
                case "id":
                    if (!reader.TryGetInt64(out var parsedId))
                    {
                        throw new InvalidOperationException("Tracked browser protocol response id was not an integer.");
                    }

                    id = parsedId;
                    break;
                case "method":
                    method = reader.TokenType == JsonTokenType.String
                        ? reader.GetString()
                        : throw new InvalidOperationException("Tracked browser protocol event method was not a string.");
                    break;
                case "sessionId":
                    sessionId = reader.TokenType == JsonTokenType.String
                        ? reader.GetString()
                        : null;
                    break;
                default:
                    reader.Skip();
                    break;
            }

View on GitHub (pinned to 25830f84bd)