[[["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-08-07 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eMessageParser\u003c/code\u003e class is a general parser used for reflection-based code, returning simple \u003ccode\u003eIMessage\u003c/code\u003e objects.\u003c/p\u003e\n"],["\u003cp\u003eIt offers methods like \u003ccode\u003eParseFrom\u003c/code\u003e and \u003ccode\u003eParseDelimitedFrom\u003c/code\u003e to parse messages from various sources, including streams, byte strings, and byte arrays.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eParseJson\u003c/code\u003e method allows parsing messages from JSON strings, although it does not support ignoring unknown fields without using a custom \u003ccode\u003eJsonParser\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eYou can create modified message parsers with \u003ccode\u003eWithDiscardUnknownFields\u003c/code\u003e to control the handling of unknown fields, and \u003ccode\u003eWithExtensionRegistry\u003c/code\u003e to register extensions.\u003c/p\u003e\n"],["\u003cp\u003eThe class inherits several members from \u003ccode\u003eobject\u003c/code\u003e, such as \u003ccode\u003eEquals\u003c/code\u003e, \u003ccode\u003eGetHashCode\u003c/code\u003e, and \u003ccode\u003eToString\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Class MessageParser (3.27.1)\n\nVersion latestkeyboard_arrow_down\n\n- [3.27.1 (latest)](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageParser)\n- [3.23.0](/dotnet/docs/reference/Google.Protobuf/3.23.0/Google.Protobuf.MessageParser)\n- [3.15.8](/dotnet/docs/reference/Google.Protobuf/3.15.8/Google.Protobuf.MessageParser) \n\n public class MessageParser\n\nA general message parser, typically used by reflection-based code as all the methods\nreturn simple [IMessage](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage). \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e MessageParser \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\nDerived Types\n-------------\n\n[MessageParser\\\u003cT\\\u003e](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageParser-1)\n\nNamespace\n---------\n\n[Google.Protobuf](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf)\n\nAssembly\n--------\n\nGoogle.Protobuf.dll\n\nMethods\n-------\n\n### ParseDelimitedFrom(Stream)\n\n public IMessage ParseDelimitedFrom(Stream input)\n\nParses a length-delimited message from the given stream.\n\n**Remarks** \nThe stream is expected to contain a length and then the data. Only the amount of data\nspecified by the length will be consumed.\n\n### ParseFrom(ByteString)\n\n public IMessage ParseFrom(ByteString data)\n\nParses a message from the given byte string.\n\n### ParseFrom(CodedInputStream)\n\n public IMessage ParseFrom(CodedInputStream input)\n\nParses a message from the given coded input stream.\n\n### ParseFrom(ReadOnlySequence\\\u003cbyte\\\u003e)\n\n public IMessage ParseFrom(ReadOnlySequence\u003cbyte\u003e data)\n\nParses a message from the given sequence.\n\n### ParseFrom(byte\\[\\])\n\n public IMessage ParseFrom(byte[] data)\n\nParses a message from a byte array.\n\n### ParseFrom(byte\\[\\], int, int)\n\n public IMessage ParseFrom(byte[] data, int offset, int length)\n\nParses a message from a byte array slice.\n\n### ParseFrom(Stream)\n\n public IMessage ParseFrom(Stream input)\n\nParses a message from the given stream.\n\n### ParseFrom(ReadOnlySpan\\\u003cbyte\\\u003e)\n\n public IMessage ParseFrom(ReadOnlySpan\u003cbyte\u003e data)\n\nParses a message from the given span.\n\n### ParseJson(string)\n\n public IMessage ParseJson(string json)\n\nParses a message from the given JSON.\n\n**Remarks** \nThis method always uses the default JSON parser; it is not affected by [WithDiscardUnknownFields(bool)](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageParser#Google_Protobuf_MessageParser_WithDiscardUnknownFields_System_Boolean_).\nTo ignore unknown fields when parsing JSON, create a [JsonParser](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonParser) using a [JsonParser.Settings](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonParser.Settings)\nwith [IgnoreUnknownFields](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonParser.Settings#Google_Protobuf_JsonParser_Settings_IgnoreUnknownFields) set to true and call [Parse\\\u003cT\\\u003e(string)](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonParser#Google_Protobuf_JsonParser_Parse__1_System_String_) directly.\n\n### WithDiscardUnknownFields(bool)\n\n public MessageParser WithDiscardUnknownFields(bool discardUnknownFields)\n\nCreates a new message parser which optionally discards unknown fields when parsing.\n\n**Remarks** \nNote that this does not affect the behavior of [ParseJson(string)](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageParser#Google_Protobuf_MessageParser_ParseJson_System_String_)\nat all. To ignore unknown fields when parsing JSON, create a [JsonParser](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonParser) using a [JsonParser.Settings](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonParser.Settings)\nwith [IgnoreUnknownFields](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonParser.Settings#Google_Protobuf_JsonParser_Settings_IgnoreUnknownFields) set to true and call [Parse\\\u003cT\\\u003e(string)](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonParser#Google_Protobuf_JsonParser_Parse__1_System_String_) directly.\n\n### WithExtensionRegistry(ExtensionRegistry)\n\n public MessageParser WithExtensionRegistry(ExtensionRegistry registry)\n\nCreates a new message parser which registers extensions from the specified registry upon creating the message instance"]]