Skip to content

Fix dotnet-pgo dump crash when CallWeights are present#125936

Merged
eiriktsarpalis merged 1 commit intodotnet:mainfrom
benaadams:fix/dotnet-pgo-dump-callweights
Mar 23, 2026
Merged

Fix dotnet-pgo dump crash when CallWeights are present#125936
eiriktsarpalis merged 1 commit intodotnet:mainfrom
benaadams:fix/dotnet-pgo-dump-callweights

Conversation

@benaadams
Copy link
Member

Summary

Fix InvalidOperationException in dotnet-pgo dump when the .mibc file contains CallWeights data.

Problem

The JSON serialization writes named properties (Method, Weight) directly inside a JSON array without wrapping each entry in a JSON object:

jsonWriter.WriteStartArray("CallWeights");
foreach (var callWeight in data.CallWeights)
{
    jsonWriter.WriteString("Method", ...);  // crash: property inside array
    jsonWriter.WriteNumber("Weight", ...);
}

Fix

Add WriteStartObject() / WriteEndObject() around each array entry.

Fixes #125935

The JSON serialization of CallWeights in the dump command writes named
properties (Method, Weight) directly inside a JSON array without
wrapping each entry in an object, causing InvalidOperationException.

Add WriteStartObject/WriteEndObject around each CallWeights entry.

Fixes dotnet#125935
Copilot AI review requested due to automatic review settings March 23, 2026 00:16
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 23, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes dotnet-pgo dump JSON generation for .mibc files that include CallWeights by ensuring each array element is a proper JSON object, preventing Utf8JsonWriter from throwing when writing named properties inside an array.

Changes:

  • Wrap each CallWeights entry with WriteStartObject() / WriteEndObject() during dump JSON serialization.

@eiriktsarpalis eiriktsarpalis enabled auto-merge (squash) March 23, 2026 11:27
@eiriktsarpalis
Copy link
Member

/ba-g test failure is unrelated

@eiriktsarpalis eiriktsarpalis merged commit 875672f into dotnet:main Mar 23, 2026
104 of 109 checks passed
@benaadams benaadams deleted the fix/dotnet-pgo-dump-callweights branch March 23, 2026 12:20
eiriktsarpalis pushed a commit that referenced this pull request Mar 23, 2026
## Summary

Fix `InvalidOperationException` in `dotnet-pgo dump` when the .mibc file
contains CallWeights data.

## Problem

The JSON serialization writes named properties (`Method`, `Weight`)
directly inside a JSON array without wrapping each entry in a JSON
object:

```csharp
jsonWriter.WriteStartArray("CallWeights");
foreach (var callWeight in data.CallWeights)
{
    jsonWriter.WriteString("Method", ...);  // crash: property inside array
    jsonWriter.WriteNumber("Weight", ...);
}
```

## Fix

Add `WriteStartObject()` / `WriteEndObject()` around each array entry.

Fixes #125935
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-VM-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dotnet-pgo dump: JSON serialization crash when CallWeights are present

4 participants