diff --git a/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs b/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs index fb83ff4e73..36a2f02229 100644 --- a/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs +++ b/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs @@ -127,7 +127,15 @@ namespace Google.Protobuf var segmentedBufferWriter = new ArrayBufferWriter(); segmentedBufferWriter.MaxGrowBy = blockSize; message.WriteTo(segmentedBufferWriter); - Assert.AreEqual(bytes, bufferWriter.WrittenSpan.ToArray()); + Assert.AreEqual(bytes, segmentedBufferWriter.WrittenSpan.ToArray()); + } + + // if the full message is small enough, try serializing directly into stack-allocated buffer + if (bytes.Length <= 256) + { + Span stackAllocBuffer = stackalloc byte[bytes.Length]; + message.WriteTo(stackAllocBuffer); + Assert.AreEqual(bytes, stackAllocBuffer.ToArray()); } } }