From 6bf22b892bead9d84264e0513d905dc3a683882f Mon Sep 17 00:00:00 2001
From: Jon Skeet <jonskeet@google.com>
Date: Fri, 17 Mar 2023 14:13:07 +0000
Subject: [PATCH] Fix compile-time error for Google.Protobuf in C# 11

Note that the error only affects users trying to build
Google.Protobuf directly using C# 11. It doesn't affect users who
are compiling code against the pre-built library (which is likely to
be basically everyone).

Fixes #11004.
---
 csharp/src/Google.Protobuf/ParseContext.cs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/csharp/src/Google.Protobuf/ParseContext.cs b/csharp/src/Google.Protobuf/ParseContext.cs
index 85ea56737a..58a3eef45a 100644
--- a/csharp/src/Google.Protobuf/ParseContext.cs
+++ b/csharp/src/Google.Protobuf/ParseContext.cs
@@ -64,8 +64,9 @@ namespace Google.Protobuf
             state.recursionLimit = DefaultRecursionLimit;
             state.currentLimit = int.MaxValue;
             state.bufferSize = buffer.Length;
-
-            Initialize(buffer, ref state, out ctx);
+            // Equivalent to Initialize(buffer, ref state, out ctx);
+            ctx.buffer = buffer;
+            ctx.state = state;
         }
 
         /// <summary>
@@ -74,6 +75,7 @@ namespace Google.Protobuf
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         internal static void Initialize(ReadOnlySpan<byte> buffer, ref ParserInternalState state, out ParseContext ctx)
         {
+            // Note: if this code ever changes, also change the initialization above.
             ctx.buffer = buffer;
             ctx.state = state;
         }