Trying to run some benchmarks for an application target .NET 11 using the latest CI build (0.16.0-nightly.20260331.487), trying to read the file contents output via --json in a JavaScript GitHub Action parsing the JSON is failing.
Error: Error: Failed to parse '/home/runner/work/costellobot/costellobot/BenchmarkDotNet.Artifacts/results/MartinCostello.Costellobot.Benchmarks.AppBenchmarks-report-full-compressed.json' as BenchmarkDotNet JSON output. Results must be a JSON file generated with the '--exporters json' option: SyntaxError: Unexpected token '', "{"Title":"... is not valid JSON
This is what the code in my action does:
const json = await fs.promises.readFile(fileName, { encoding: 'utf8' });
return JSON.parse(json);
After some debugging and pasting the content into https://repljs.com/ I spotted this:
Looks like the refactoring in #2970 to remove SimpleJson has changed the default encoding to UTF-8 with a Byte Order Mark.
I'm guessing this is an unintentional change caused by the System.Text.Json defaults?
|
private static readonly JsonSerializerOptions DefaultOptions = new() |
|
{ |
|
Converters = |
|
{ |
|
new SimpleJsonFloatConverter(), |
|
new SimpleJsonDoubleConverter(), |
|
}, |
|
// Disable escaping non ASCII chars. https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/character-encoding#serialize-all-characters |
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, |
|
TypeInfoResolverChain = |
|
{ |
|
// Use Reflection based serialization/deserialization. Because Summary object contains anonymous type. |
|
new DefaultJsonTypeInfoResolver(), |
|
}, |
|
RespectNullableAnnotations = true, |
|
}; |
Trying to run some benchmarks for an application target .NET 11 using the latest CI build (
0.16.0-nightly.20260331.487), trying to read the file contents output via--jsonin a JavaScript GitHub Action parsing the JSON is failing.This is what the code in my action does:
After some debugging and pasting the content into https://repljs.com/ I spotted this:
Looks like the refactoring in #2970 to remove SimpleJson has changed the default encoding to UTF-8 with a Byte Order Mark.
I'm guessing this is an unintentional change caused by the System.Text.Json defaults?
BenchmarkDotNet/src/BenchmarkDotNet/Serialization/BdnSimpleJsonSerializer.cs
Lines 13 to 28 in 2252a3b