Gets the entire payload as a newly allocated byte array.
Once the byte array is returned, the byte array becomes owned by the caller and won't be ever accessed or reused by gRPC again.
NOTE: Obtaining the buffer as a newly allocated byte array is the simplest way of accessing the payload,
but it can have important consequences in high-performance scenarios.
In particular, using this method usually requires copying of the entire buffer one extra time.
Also, allocating a new buffer each time can put excessive pressure on GC, especially if
the payload is more than 86700 bytes large (which means the newly allocated buffer will be placed in LOH,
and LOH object can only be garbage collected via a full ("stop the world") GC run).
NOTE: Deserializers are expected not to call this method (or other payload accessor methods) more than once per received message
(as there is no practical reason for doing so) andDeserializationContextimplementations are free to assume so.
Gets the entire payload as a ReadOnlySequence.
The ReadOnlySequence is only valid for the duration of the deserializer routine and the caller must not access it after the deserializer returns.
Using the read only sequence is the most efficient way to access the message payload. Where possible it allows directly
accessing the received payload without needing to perform any buffer copying or buffer allocations.
NOTE: When using this method, it is recommended to use C# 7.2 compiler to make it more useful (using Span type directly from your code requires C# 7.2)."
NOTE: Deserializers are expected not to call this method (or other payload accessor methods) more than once per received message
(as there is no practical reason for doing so) andDeserializationContextimplementations are free to assume so.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003e\u003ccode\u003eDeserializationContext\u003c/code\u003e is an abstract class that provides access to the payload during message deserialization.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ePayloadLength\u003c/code\u003e property returns the total length of the payload in bytes.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003ePayloadAsNewBuffer()\u003c/code\u003e returns the entire payload as a newly allocated byte array, which may impact performance in high-traffic situations.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003ePayloadAsReadOnlySequence()\u003c/code\u003e offers the most efficient way to access the payload, avoiding unnecessary copying or allocations, however, the sequence is only valid during the deserializer routine.\u003c/p\u003e\n"],["\u003cp\u003eThe methods \u003ccode\u003ePayloadAsNewBuffer()\u003c/code\u003e and \u003ccode\u003ePayloadAsReadOnlySequence()\u003c/code\u003e are only expected to be called a single time per received message.\u003c/p\u003e\n"]]],[],null,["# Class DeserializationContext (2.66.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.66.0 (latest)](/dotnet/docs/reference/Grpc.Core/latest/Grpc.Core.DeserializationContext)\n- [2.63.0](/dotnet/docs/reference/Grpc.Core/2.63.0/Grpc.Core.DeserializationContext)\n- [2.48.0](/dotnet/docs/reference/Grpc.Core/2.48.0/Grpc.Core.DeserializationContext) \n\n public abstract class DeserializationContext\n\nProvides access to the payload being deserialized when deserializing messages. \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e DeserializationContext \n\nInherited Members\n-----------------\n\n[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) \n[object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) \n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) \n[object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\nNamespace\n---------\n\n[Grpc.Core](/dotnet/docs/reference/Grpc.Core/latest/Grpc.Core)\n\nAssembly\n--------\n\nGrpc.Core.Api.dll\n\nProperties\n----------\n\n### PayloadLength\n\n public abstract int PayloadLength { get; }\n\nGet the total length of the payload in bytes.\n\nMethods\n-------\n\n### PayloadAsNewBuffer()\n\n public virtual byte[] PayloadAsNewBuffer()\n\nGets the entire payload as a newly allocated byte array.\nOnce the byte array is returned, the byte array becomes owned by the caller and won't be ever accessed or reused by gRPC again.\nNOTE: Obtaining the buffer as a newly allocated byte array is the simplest way of accessing the payload,\nbut it can have important consequences in high-performance scenarios.\nIn particular, using this method usually requires copying of the entire buffer one extra time.\nAlso, allocating a new buffer each time can put excessive pressure on GC, especially if\nthe payload is more than 86700 bytes large (which means the newly allocated buffer will be placed in LOH,\nand LOH object can only be garbage collected via a full (\"stop the world\") GC run).\nNOTE: Deserializers are expected not to call this method (or other payload accessor methods) more than once per received message\n(as there is no practical reason for doing so) and `DeserializationContext` implementations are free to assume so.\n\n### PayloadAsReadOnlySequence()\n\n public virtual ReadOnlySequence\u003cbyte\u003e PayloadAsReadOnlySequence()\n\nGets the entire payload as a ReadOnlySequence.\nThe ReadOnlySequence is only valid for the duration of the deserializer routine and the caller must not access it after the deserializer returns.\nUsing the read only sequence is the most efficient way to access the message payload. Where possible it allows directly\naccessing the received payload without needing to perform any buffer copying or buffer allocations.\nNOTE: When using this method, it is recommended to use C# 7.2 compiler to make it more useful (using Span type directly from your code requires C# 7.2).\"\nNOTE: Deserializers are expected not to call this method (or other payload accessor methods) more than once per received message\n(as there is no practical reason for doing so) and `DeserializationContext` implementations are free to assume so."]]