# Interface ICustomDiagnosticMessage (3.27.1)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [3.27.1 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ICustomDiagnosticMessage)
- [3.23.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/3.23.0/Google.Protobuf.ICustomDiagnosticMessage)
- [3.15.8](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/3.15.8/Google.Protobuf.ICustomDiagnosticMessage)

    public interface ICustomDiagnosticMessage : IMessage

A message type that has a custom string format for diagnostic purposes.

## Inherited Members

[IMessage.MergeFrom(CodedInputStream)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage#Google_Protobuf_IMessage_MergeFrom_Google_Protobuf_CodedInputStream_) [IMessage.WriteTo(CodedOutputStream)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage#Google_Protobuf_IMessage_WriteTo_Google_Protobuf_CodedOutputStream_) [IMessage.CalculateSize()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage#Google_Protobuf_IMessage_CalculateSize) [IMessage.Descriptor](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage#Google_Protobuf_IMessage_Descriptor)

## Namespace

[Google.Protobuf](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf)

## Assembly

Google.Protobuf.dll

## Remarks


Calling [ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring) on a generated message type normally
returns the JSON representation. If a message type implements this interface,
then the [ToDiagnosticString()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ICustomDiagnosticMessage#Google_Protobuf_ICustomDiagnosticMessage_ToDiagnosticString) method will be called instead of the regular
JSON formatting code, but only when `ToString()` is called either on the message itself
or on another message which contains it. This does not affect the normal JSON formatting of
the message.


For example, if you create a proto message representing a GUID, the internal
representation may be a `bytes` field or four `fixed32` fields. However, when debugging
it may be more convenient to see a result in the same format as [Guid](https://learn.microsoft.com/dotnet/api/system.guid) provides.

This interface extends [IMessage](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage) to avoid it accidentally being implemented
on types other than messages, where it would not be used by anything in the framework.

## Methods

### ToDiagnosticString()

    string ToDiagnosticString()

Returns a string representation of this object, for diagnostic purposes.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` | A string representation of this object, for diagnostic purposes. |

**Remarks** This method is called when a message is formatted as part of a [ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)
call. It does not affect the JSON representation used by [JsonFormatter](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter) other than
in calls to [ToDiagnosticString(IMessage)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter#Google_Protobuf_JsonFormatter_ToDiagnosticString_Google_Protobuf_IMessage_). While it is recommended
that the result is valid JSON, this is never assumed by the Protobuf library.

## Extension Methods

[MessageExtensions.IsInitialized(IMessage)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageExtensions#Google_Protobuf_MessageExtensions_IsInitialized_Google_Protobuf_IMessage_) [MessageExtensions.MergeDelimitedFrom(IMessage, Stream)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageExtensions#Google_Protobuf_MessageExtensions_MergeDelimitedFrom_Google_Protobuf_IMessage_System_IO_Stream_) [MessageExtensions.MergeFrom(IMessage, ByteString)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageExtensions#Google_Protobuf_MessageExtensions_MergeFrom_Google_Protobuf_IMessage_Google_Protobuf_ByteString_) [MessageExtensions.MergeFrom(IMessage, ReadOnlySequence\<byte\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageExtensions#Google_Protobuf_MessageExtensions_MergeFrom_Google_Protobuf_IMessage_System_Buffers_ReadOnlySequence_System_Byte__) [MessageExtensions.MergeFrom(IMessage, byte\[\])](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageExtensions#Google_Protobuf_MessageExtensions_MergeFrom_Google_Protobuf_IMessage_System_Byte___) [MessageExtensions.MergeFrom(IMessage, byte\[\], int, int)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageExtensions#Google_Protobuf_MessageExtensions_MergeFrom_Google_Protobuf_IMessage_System_Byte___System_Int32_System_Int32_) [MessageExtensions.MergeFrom(IMessage, Stream)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageExtensions#Google_Protobuf_MessageExtensions_MergeFrom_Google_Protobuf_IMessage_System_IO_Stream_) [MessageExtensions.MergeFrom(IMessage, ReadOnlySpan\<byte\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageExtensions#Google_Protobuf_MessageExtensions_MergeFrom_Google_Protobuf_IMessage_System_ReadOnlySpan_System_Byte__) [MessageExtensions.ToByteArray(IMessage)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageExtensions#Google_Protobuf_MessageExtensions_ToByteArray_Google_Protobuf_IMessage_) [MessageExtensions.ToByteString(IMessage)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageExtensions#Google_Protobuf_MessageExtensions_ToByteString_Google_Protobuf_IMessage_) [MessageExtensions.WriteDelimitedTo(IMessage, Stream)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageExtensions#Google_Protobuf_MessageExtensions_WriteDelimitedTo_Google_Protobuf_IMessage_System_IO_Stream_) [MessageExtensions.WriteTo(IMessage, IBufferWriter\<byte\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageExtensions#Google_Protobuf_MessageExtensions_WriteTo_Google_Protobuf_IMessage_System_Buffers_IBufferWriter_System_Byte__) [MessageExtensions.WriteTo(IMessage, Stream)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageExtensions#Google_Protobuf_MessageExtensions_WriteTo_Google_Protobuf_IMessage_System_IO_Stream_) [MessageExtensions.WriteTo(IMessage, Span\<byte\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.MessageExtensions#Google_Protobuf_MessageExtensions_WriteTo_Google_Protobuf_IMessage_System_Span_System_Byte__)