From a980705bdbf09577d6f1bdc03610fe895083ebbe Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 14 Apr 2020 18:16:18 +0200 Subject: [PATCH] attempt to fix CompatibilityTests --- csharp/src/Google.Protobuf/Collections/MapField.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/csharp/src/Google.Protobuf/Collections/MapField.cs b/csharp/src/Google.Protobuf/Collections/MapField.cs index 9ed86e80c..e41af378c 100644 --- a/csharp/src/Google.Protobuf/Collections/MapField.cs +++ b/csharp/src/Google.Protobuf/Collections/MapField.cs @@ -716,8 +716,17 @@ namespace Google.Protobuf.Collections // Read it as if we'd seen input with no data (i.e. create a "default" message). if (Value == null) { - ParseContext.Initialize(new ReadOnlySequence(ZeroLengthMessageStreamData), out ParseContext zeroLengthCtx); - Value = codec.valueCodec.Read(ref zeroLengthCtx); + if (ctx.state.codedInputStream != null) + { + // the decoded message might not support parsing from ParseContext, so + // we need to allow fallback to the legacy MergeFrom(CodedInputStream) parsing. + Value = codec.valueCodec.Read(new CodedInputStream(ZeroLengthMessageStreamData)); + } + else + { + ParseContext.Initialize(new ReadOnlySequence(ZeroLengthMessageStreamData), out ParseContext zeroLengthCtx); + Value = codec.valueCodec.Read(ref zeroLengthCtx); + } } }