KirillOsenkov / MSBuildStructuredLog

A logger for MSBuild that records a structured representation of executed targets, tasks, property and item values.
MIT License
1.47k stars 198 forks source link

Error when reading the file created in Rider #740

Closed real-mikhail closed 10 months ago

real-mikhail commented 10 months ago

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.

KirillOsenkov commented 10 months ago

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

shmuelie commented 10 months ago

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

JanKrivanek commented 10 months ago

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

KirillOsenkov commented 10 months ago

Confirmed the binlog opens fine with https://github.com/KirillOsenkov/MSBuildStructuredLog/commit/ca260010d61647759ff3d54cfd5cd4707e31b8fa and fails to open with the latest main

KirillOsenkov commented 10 months ago

This is related to reading ProjectEvaluationFinishedEventArgs:

image

KirillOsenkov commented 10 months ago

The problem is here: https://github.com/KirillOsenkov/MSBuildStructuredLog/blob/7901b7f3098b3cca6770de56d547856ce84b5fa2/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs#L726-L731

Compare to before: https://github.com/KirillOsenkov/MSBuildStructuredLog/blob/ca260010d61647759ff3d54cfd5cd4707e31b8fa/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs#L568-L572

KirillOsenkov commented 10 months ago

@JanKrivanek I'm trying to understand this change above

KirillOsenkov commented 10 months ago

I pushed out a mitigation here: https://github.com/KirillOsenkov/MSBuildStructuredLog/commit/d72b8bf03472252dbee60755721539bc38a13010

KirillOsenkov commented 10 months ago

Unlisted https://www.nuget.org/packages/binlogtool/1.0.10 Unlisted https://www.nuget.org/packages/MSBuild.StructuredLogger/2.2.155

KirillOsenkov commented 10 months ago

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.

KirillOsenkov commented 10 months ago

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

shmuelie commented 10 months ago

Yup, works now!

real-mikhail commented 10 months ago

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