Rename MicroBenchmarks.Serializers.BinaryData to BinaryDataPayload#5216
Merged
DrewScoggins merged 1 commit intodotnet:mainfrom May 7, 2026
Merged
Conversation
The serialization-test helper class `MicroBenchmarks.Serializers.BinaryData` shadowed the in-box `System.BinaryData` type (introduced in net6+ via `System.Memory.Data`, brought in transitively by Azure.Core). Inside `DataGenerator.cs` (namespace MicroBenchmarks.Serializers) the unqualified `typeof(BinaryData)` always bound to the local helper class. Inside `ReadJson.cs` / `WriteJson.cs` (namespace System.Text.Json.Serialization.Tests) C# enclosing-namespace lookup found `System.BinaryData` first, so the `[GenericTypeArguments(typeof(BinaryData))]` attribute resolved to a DIFFERENT type than the `Generate<T>()` switch was checking. The mismatch was latent on main (where System.Memory.Data wasn't compile-visible to ReadJson.cs) but surfaced as `System.NotImplementedException` in `DataGenerator.Generate<T>()` whenever the reference closure changed (e.g. retargeting BenchmarkDotNet.Extensions from netstandard2.0 to net8.0). Renaming the helper class to `BinaryDataPayload` removes the shadowing once and for all. No behavior change on main; future-proofs against reference-closure churn. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request renames the microbenchmark serialization helper type MicroBenchmarks.Serializers.BinaryData to BinaryDataPayload to avoid shadowing System.BinaryData (net6+), which could cause GenericTypeArguments to bind to the wrong type and trigger runtime NotImplementedException in DataGenerator.Generate<T>().
Changes:
- Renamed the local helper model
BinaryDatatoBinaryDataPayloadinDataGenerator.cs. - Updated
DataGenerator.Generate<T>()and JSON source-generator registration to useBinaryDataPayload. - Updated
ReadJson<T>/WriteJson<T>benchmark generic type argument lists to referenceBinaryDataPayload.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/benchmarks/micro/Serializers/DataGenerator.cs | Renames the helper model and updates generator/type registrations to eliminate System.BinaryData shadowing issues. |
| src/benchmarks/micro/libraries/System.Text.Json/Serializer/WriteJson.cs | Updates benchmark generic type argument from BinaryData to BinaryDataPayload. |
| src/benchmarks/micro/libraries/System.Text.Json/Serializer/ReadJson.cs | Updates benchmark generic type argument from BinaryData to BinaryDataPayload. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
LoopedBard3
approved these changes
May 7, 2026
This was referenced May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description from copilot.
The serialization-test helper class
MicroBenchmarks.Serializers.BinaryDatashadowed the in-boxSystem.BinaryDatatype (introduced in net6+ viaSystem.Memory.Data, brought in transitively by Azure.Core).Inside
DataGenerator.cs(namespace MicroBenchmarks.Serializers) the unqualifiedtypeof(BinaryData)always bound to the local helper class. InsideReadJson.cs/WriteJson.cs(namespace System.Text.Json.Serialization.Tests) C# enclosing-namespace lookup foundSystem.BinaryDatafirst, so the[GenericTypeArguments(typeof(BinaryData))]attribute resolved to a DIFFERENT type than theGenerate<T>()switch was checking. The mismatch was latent on main (where System.Memory.Data wasn't compile-visible to ReadJson.cs) but surfaced asSystem.NotImplementedExceptioninDataGenerator.Generate<T>()whenever the reference closure changed (e.g. retargeting BenchmarkDotNet.Extensions from netstandard2.0 to net8.0).Renaming the helper class to
BinaryDataPayloadremoves the shadowing once and for all. No behavior change on main; future-proofs against reference-closure churn.