System.Formats.Nrbf 9.0.17

About

System.Formats.Nrbf exposes only one component: NrbfDecoder: a stateless, forward-only decoder class that can decode .NET Remoting Binary Format (NRBF) binary data from a stream.

You can think of NrbfDecoder as being the equivalent of using a JSON/XML reader without the deserializer.

Note: The 9.0.0 release of the System.Formats.Nrbf package is marked [Experimental] as the API shape is subject to change in the next major release. Even with the experimental annotation, the package is officially supported. Using the APIs from this package will produce a build warning with diagnostic ID SYSLIB5005. The diagnostic can be suppressed with the acknowledgement that the API shape is subject to change in the next major release.

How to Use

The NRBF payload consists of serialization records that represent the serialized objects and their metadata. To read the whole payload and get the root record, you need to call one of the NrbfDecoder.Decode methods.

The Decode method returns a SerializationRecord instance. SerializationRecord is an abstract class that represents the serialization record and provides three properties: Id, RecordType, and TypeName. It exposes one method, TypeNameMatches, which compares the type name read from the payload (and exposed via TypeName property) against the specified type. This method ignores assembly names, so you don't need to worry about type forwarding and assembly versioning. It also does not consider member names or their types (because getting this information would require type loading).

using System.Formats.Nrbf;

public class Sample
{
    public int Integer;
    public string? Text;
    public byte[]? ArrayOfBytes;
    public Sample? ClassInstance;
}

ClassRecord rootRecord = NrbfDecoder.DecodeClassRecord(payload);
Sample output = new()
{
    // using the dedicated methods to read primitive values
    Integer = rootRecord.GetInt32(nameof(Sample.Integer)),
    Text = rootRecord.GetString(nameof(Sample.Text)),
    // using dedicated method to read an array of bytes
    ArrayOfBytes = ((SZArrayRecord<byte>)rootRecord.GetArrayRecord(nameof(Sample.ArrayOfBytes))).GetArray(),
    // using GetClassRecord to read a class record
    ClassInstance = new()
    {
        Text = rootRecord
            .GetClassRecord(nameof(Sample.ClassInstance))!
            .GetString(nameof(Sample.Text))
    }
};

Main Types

There are more than a dozen different serialization record types. This library provides a set of abstractions, so you only need to learn a few of them:

  • PrimitiveTypeRecord<T>: describes all primitive types natively supported by the NRBF (string, bool, byte, sbyte, char, short, ushort, int, uint, long, ulong, float, double, decimal, TimeSpan, and DateTime).
    • Exposes the value via the Value property.
    • PrimitiveTypeRecord<T> derives from the non-generic PrimitiveTypeRecord, which also exposes a Value property. But on the base class, the value is returned as object (which introduces boxing for value types).
  • ClassRecord: describes all class and struct besides the aforementioned primitive types.
  • ArrayRecord: describes all array records, including jagged and multi-dimensional arrays.
  • SZArrayRecord<T>: describes single-dimensional, zero-indexed array records, where T can be either a primitive type or a SerializationRecord.
SerializationRecord rootObject = NrbfDecoder.Decode(payload); // payload is a Stream

if (rootObject is PrimitiveTypeRecord primitiveRecord)
{
    Console.WriteLine($"It was a primitive value: '{primitiveRecord.Value}'");
}
else if (rootObject is ClassRecord classRecord)
{
    Console.WriteLine($"It was a class record of '{classRecord.TypeName.AssemblyQualifiedName}' type name.");
}
else if (rootObject is SZArrayRecord<byte> arrayOfBytes)
{
    Console.WriteLine($"It was an array of `{arrayOfBytes.Length}`-many bytes.");
}

Additional Documentation

Feedback & Contributing

System.Formats.Nrbf is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

Showing the top 20 packages that depend on System.Formats.Nrbf.

Packages Downloads
Microsoft.Build.Tasks.Core
This package contains the Microsoft.Build.Tasks assembly which implements the commonly used tasks of MSBuild.
96
Microsoft.Build.Tasks.Core
This package contains the Microsoft.Build.Tasks assembly which implements the commonly used tasks of MSBuild.
97
Microsoft.Build.Tasks.Core
This package contains the Microsoft.Build.Tasks assembly which implements the commonly used tasks of MSBuild.
106
Microsoft.Build.Tasks.Core
This package contains the Microsoft.Build.Tasks assembly which implements the commonly used tasks of MSBuild.
114
Microsoft.Build.Tasks.Core
This package contains the Microsoft.Build.Tasks assembly which implements the commonly used tasks of MSBuild.
122
System.Resources.Extensions
Provides classes which read and write resources in a format that supports non-primitive objects. Commonly Used Types: System.Resources.Extensions.DeserializingResourceReader System.Resources.Extensions.PreserializedResourceWriter
94
System.Resources.Extensions
Provides classes which read and write resources in a format that supports non-primitive objects. Commonly Used Types: System.Resources.Extensions.DeserializingResourceReader System.Resources.Extensions.PreserializedResourceWriter
95
System.Resources.Extensions
Provides classes which read and write resources in a format that supports non-primitive objects. Commonly Used Types: System.Resources.Extensions.DeserializingResourceReader System.Resources.Extensions.PreserializedResourceWriter
101
System.Resources.Extensions
Provides classes which read and write resources in a format that supports non-primitive objects. Commonly Used Types: System.Resources.Extensions.DeserializingResourceReader System.Resources.Extensions.PreserializedResourceWriter
102
System.Resources.Extensions
Provides classes which read and write resources in a format that supports non-primitive objects. Commonly Used Types: System.Resources.Extensions.DeserializingResourceReader System.Resources.Extensions.PreserializedResourceWriter
107
System.Resources.Extensions
Provides classes which read and write resources in a format that supports non-primitive objects. Commonly Used Types: System.Resources.Extensions.DeserializingResourceReader System.Resources.Extensions.PreserializedResourceWriter
111
System.Resources.Extensions
Provides classes which read and write resources in a format that supports non-primitive objects. Commonly Used Types: System.Resources.Extensions.DeserializingResourceReader System.Resources.Extensions.PreserializedResourceWriter
112
System.Resources.Extensions
Provides classes which read and write resources in a format that supports non-primitive objects. Commonly Used Types: System.Resources.Extensions.DeserializingResourceReader System.Resources.Extensions.PreserializedResourceWriter
113
System.Resources.Extensions
Provides classes which read and write resources in a format that supports non-primitive objects. Commonly Used Types: System.Resources.Extensions.DeserializingResourceReader System.Resources.Extensions.PreserializedResourceWriter
114
System.Resources.Extensions
Provides classes which read and write resources in a format that supports non-primitive objects. Commonly Used Types: System.Resources.Extensions.DeserializingResourceReader System.Resources.Extensions.PreserializedResourceWriter
119
System.Resources.Extensions
Provides classes which read and write resources in a format that supports non-primitive objects. Commonly Used Types: System.Resources.Extensions.DeserializingResourceReader System.Resources.Extensions.PreserializedResourceWriter
123
System.Resources.Extensions
Provides classes which read and write resources in a format that supports non-primitive objects. Commonly Used Types: System.Resources.Extensions.DeserializingResourceReader System.Resources.Extensions.PreserializedResourceWriter
130
System.Resources.Extensions
Provides classes which read and write resources in a format that supports non-primitive objects. Commonly Used Types: System.Resources.Extensions.DeserializingResourceReader System.Resources.Extensions.PreserializedResourceWriter
147

https://go.microsoft.com/fwlink/?LinkID=799421

.NET Framework 4.6.2

.NET 8.0

.NET 9.0

  • No dependencies.

.NET Standard 2.0

Version Downloads Last updated
11.0.0-preview.5.26302.115 7 06/11/2026
11.0.0-preview.4.26230.115 8 05/14/2026
11.0.0-preview.3.26207.106 19 04/14/2026
11.0.0-preview.2.26159.112 32 03/12/2026
11.0.0-preview.1.26104.118 30 02/13/2026
10.0.9 8 06/11/2026
10.0.8 12 05/14/2026
10.0.7 24 04/21/2026
10.0.6 25 04/14/2026
10.0.5 26 03/13/2026
10.0.4 27 03/12/2026
10.0.3 29 02/13/2026
10.0.2 28 01/13/2026
10.0.1 45 12/11/2025
10.0.0 66 11/12/2025
10.0.0-rc.2.25502.107 67 10/15/2025
10.0.0-rc.1.25451.107 98 09/10/2025
10.0.0-preview.7.25380.108 89 08/14/2025
10.0.0-preview.6.25358.103 78 07/16/2025
10.0.0-preview.5.25277.114 97 06/10/2025
10.0.0-preview.4.25258.110 90 05/16/2025
10.0.0-preview.3.25171.5 96 04/12/2025
10.0.0-preview.2.25163.2 99 04/02/2025
10.0.0-preview.1.25080.5 95 04/04/2025
9.0.17 6 06/11/2026
9.0.16 12 05/14/2026
9.0.15 19 04/14/2026
9.0.14 20 03/12/2026
9.0.13 30 02/13/2026
9.0.12 38 01/13/2026
9.0.11 63 11/12/2025
9.0.10 88 10/15/2025
9.0.9 79 09/10/2025
9.0.8 80 08/09/2025
9.0.7 94 07/11/2025
9.0.6 106 06/12/2025
9.0.5 122 05/17/2025
9.0.4 96 04/12/2025
9.0.3 96 04/01/2025
9.0.2 105 04/01/2025
9.0.1 109 04/01/2025
9.0.0 116 11/14/2024
9.0.0-rc.2.24473.5 106 10/23/2024
9.0.0-rc.1.24431.7 111 10/21/2024
9.0.0-preview.7.24405.7 103 08/21/2024
9.0.0-preview.6.24327.7 115 07/22/2024