瀏覽代碼

attempt to fix CompatibilityTests

Jan Tattermusch 5 年之前
父節點
當前提交
a980705bdb
共有 1 個文件被更改,包括 11 次插入2 次删除
  1. 11 2
      csharp/src/Google.Protobuf/Collections/MapField.cs

+ 11 - 2
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<byte>(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<byte>(ZeroLengthMessageStreamData), out ParseContext zeroLengthCtx);
+                            Value = codec.valueCodec.Read(ref zeroLengthCtx);
+                        }
                     }
                 }