KirillOsenkov/MSBuildStructuredLog

Error when reading the file created in Rider

real-mikhail opened this issue · 13 comments

Binlog is created on empty .NET solution via Rider 2023.3.2 (Reload Project and Show Logs action).
I'm not sure whether the issue is on Rider side or in MSBuild Structured Log Viewer but I assume that Rider is using standard way to create binlog.

Program version: 2.2.155

The error:

Error when reading the file: System.IO.InvalidDataException: BuildEvent record number 1047 (serialized size: 0) attempted to perform disallowed reads (details: System.IO.InvalidDataException: String record number 1047 is invalid: string index 771 is not within 768.). ---> System.IO.InvalidDataException: String record number 1047 is invalid: string index 771 is not within 768.
   at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.GetStringFromRecord(Int32 index) in C:\projects\msbuildstructuredlog\src\StructuredLogger\BinaryLogger\BuildEventArgsReader.cs:line 1776
   at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.ReadEvaluationLocation() in C:\projects\msbuildstructuredlog\src\StructuredLogger\BinaryLogger\BuildEventArgsReader.cs:line 1824
   at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.ReadProjectEvaluationFinishedEventArgs() in C:\projects\msbuildstructuredlog\src\StructuredLogger\BinaryLogger\BuildEventArgsReader.cs:line 752
   at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.ReadBuildEventArgs(BinaryLogRecordKind recordKind) in C:\projects\msbuildstructuredlog\src\StructuredLogger\BinaryLogger\BuildEventArgsReader.cs:line 314
   at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.Read() in C:\projects\msbuildstructuredlog\src\StructuredLogger\BinaryLogger\BuildEventArgsReader.cs:line 236
   --- End of inner exception stack trace ---
   at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.<Read>g__HandleError|45_0(FormatErrorMessage msgFactory, Boolean noThrow, ReaderErrorType readerErrorType, BinaryLogRecordKind recordKind, Exception innerException) in C:\projects\msbuildstructuredlog\src\StructuredLogger\BinaryLogger\BuildEventArgsReader.cs:line 291
   at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.Read() in C:\projects\msbuildstructuredlog\src\StructuredLogger\BinaryLogger\BuildEventArgsReader.cs:line 254
   at Microsoft.Build.Logging.StructuredLogger.BinLogReader.Replay(Stream stream, Progress progress) in C:\projects\msbuildstructuredlog\src\StructuredLogger\BinaryLogger\BinLogReader.cs:line 91

I'm attaching repro solution and binlog.

@JanKrivanek FYI in case you can see what could be going wrong

I'm running into this for any binfile I try to open.

Unfortunately AFK, so can only debug in couple hours.
But on a first sight - for some reason a new format (with offsets) seem to be assumed, while rhe logs are likely version <17

Confirmed the binlog opens fine with ca26001 and fails to open with the latest main

This is related to reading ProjectEvaluationFinishedEventArgs:

image

The problem is here:

if (_fileFormatVersion < BinaryLogger.ForwardCompatibilityMinimalVersion)
{
// Throw away, but need to advance past it
ReadBoolean();
}
IEnumerable? globalProperties = ReadStringDictionary();

Compare to before:

IEnumerable globalProperties = null;
if (ReadBoolean())
{
globalProperties = ReadStringDictionary();
}

@JanKrivanek I'm trying to understand this change above

I pushed out a mitigation here:
d72b8bf

I pushed out 2.2.156 of the binlog viewer:
https://github.com/KirillOsenkov/MSBuildStructuredLog/releases/tag/v2.2.156

It should be reading existing binlogs correctly.

@JanKrivanek there's no urgency in mitigating this now. You can take your time and do it later this week or whenever.

@real-mikhail @shmuelie if you could please try the version 2.2.156 that I just released

Yup, works now!

Yes, the issue is gone. Thank you so much for the quick response and fix!