diff --git a/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs b/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs index 7b40c84f4be..965683a76b2 100644 --- a/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs +++ b/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs @@ -220,13 +220,16 @@ public void WriteBlob(BinaryLogRecordKind kind, byte[] bytes) public void WriteBlob(BinaryLogRecordKind kind, Stream stream) { - // write the blob directly to the underlying writer, - // bypassing the memory stream - using var redirection = RedirectWritesToOriginalWriter(); + if (stream.Length <= int.MaxValue) + { + // write the blob directly to the underlying writer, + // bypassing the memory stream + using var redirection = RedirectWritesToOriginalWriter(); - Write(kind); - Write(stream.Length); - Write(stream); + Write(kind); + Write((int)stream.Length); + Write(stream); + } } ///