System.Memory.Data 1.0.0

System.Memory.Data library for .NET

Binary Data

The BinaryData type provides a lightweight abstraction for a payload of bytes. It provides convenient helper methods to get out commonly used primitives, such as streams, strings, or bytes. The assumption when converting to and from string is that the encoding is UTF-8.

Data ownership

When using the byte[] or ReadOnlyMemory<byte> constructors or methods, BinaryData will wrap the passed in bytes. When using streams, strings, or rich model types that will be serialized as Json, the data is converted into bytes and will be maintained by BinaryData. Thus, if you are using bytes to create your instance of BinaryData, changes to the underlying data will be reflected in BinaryData as it does not copy the bytes.

Usage

The main value of this type is its ability to easily convert from string to bytes to stream. This can greatly simplify API surface areas by exposing this type as opposed to numerous overloads or properties.

To/From string:

var data = new BinaryData("some data");

// ToString will decode the bytes using UTF-8
Console.WriteLine(data.ToString()); // prints "some data"

To/From bytes:

byte[] bytes = Encoding.UTF8.GetBytes("some data");

// Create BinaryData using a constructor ...
BinaryData data = new BinaryData(bytes);

// Or using a static factory method.
data = BinaryData.FromBytes(bytes);

// There is an implicit cast defined for ReadOnlyMemory<byte>
ReadOnlyMemory<byte> rom = data;

// There is also an implicit cast defined for ReadOnlySpan<byte>
ReadOnlySpan<byte> ros = data;

// there is also a ToMemory method that gives access to the ReadOnlyMemory.
rom = data.ToMemory();

// and a ToArray method that converts into a byte array.
byte[] array = data.ToArray();

To/From stream:

var bytes = Encoding.UTF8.GetBytes("some data");
Stream stream = new MemoryStream(bytes);
var data = BinaryData.FromStream(stream);

// Calling ToStream will give back a stream that is backed by ReadOnlyMemory, so it is not writable.
stream = data.ToStream();
Console.WriteLine(stream.CanWrite); // prints false

BinaryData also can be used to integrate with ObjectSerializer. By default, the JsonObjectSerializer will be used, but any serializer deriving from ObjectSerializer can be used.

var model = new CustomModel
{
    A = "some text",
    B = 5,
    C = true
};

var data = BinaryData.FromObjectAsJson(model);
model = data.ToObjectFromJson<CustomModel>();

Showing the top 20 packages that depend on System.Memory.Data.

Packages Downloads
Azure.Core
This is the implementation of the Azure Client Pipeline
137
System.ClientModel
Contains building blocks for clients that call cloud services.
135
Azure.Core
This is the implementation of the Azure Client Pipeline
45
Azure.Core
This is the implementation of the Azure Client Pipeline
34
Azure.Core
This is the implementation of the Azure Client Pipeline
32
Azure.Core
This is the implementation of the Azure Client Pipeline
31
Azure.Core
This is the implementation of the Azure Client Pipeline
30
Azure.Core
This is the implementation of the Azure Client Pipeline
29
Azure.Core
This is the implementation of the Azure Client Pipeline
28
Azure.Core
This is the implementation of the Azure Client Pipeline
27
Azure.Core.Amqp
This library contains AMQP model types used by Azure libraries.
25
Azure.Core
This is the implementation of the Azure Client Pipeline
25
Azure.Core
This is the implementation of the Azure Client Pipeline
24
Azure.Core
This is the implementation of the Azure Client Pipeline
23

.NET Framework 4.6.1

.NET Standard 2.0

Version Downloads Last updated
11.0.0 0 11/10/2026
11.0.0-rc.3.26522.148 2 11/03/2026
11.0.0-rc.2.26504.105 10 10/19/2026
11.0.0-rc.1.26425.128 9 09/10/2026
11.0.0-preview.7.26381.103 13 08/11/2026
11.0.0-preview.6.26359.118 14 07/16/2026
11.0.0-preview.5.26302.115 16 06/25/2026
11.0.0-preview.4.26230.115 19 05/14/2026
11.0.0-preview.3.26207.106 21 04/21/2026
11.0.0-preview.2.26159.112 15 03/21/2026
11.0.0-preview.1.26104.118 14 02/19/2026
10.0.15 0 11/10/2026
10.0.14 2 11/07/2026
10.0.13 6 11/04/2026
10.0.12 13 09/12/2026
10.0.11 16 08/20/2026
10.0.10 10 07/19/2026
10.0.9 9 06/25/2026
10.0.8 13 05/14/2026
10.0.7 16 06/25/2026
10.0.6 12 04/21/2026
10.0.5 15 03/21/2026
10.0.4 23 03/21/2026
10.0.3 19 03/04/2026
10.0.2 16 02/19/2026
10.0.1 14 03/21/2026
10.0.0 16 12/03/2025
10.0.0-rc.2.25502.107 19 06/26/2026
10.0.0-rc.1.25451.107 23 09/14/2025
10.0.0-preview.7.25380.108 14 08/24/2025
10.0.0-preview.6.25358.103 13 06/25/2026
10.0.0-preview.5.25277.114 15 06/22/2025
10.0.0-preview.4.25258.110 13 06/27/2026
10.0.0-preview.3.25171.5 14 07/07/2026
10.0.0-preview.2.25163.2 10 06/25/2026
10.0.0-preview.1.25080.5 10 07/07/2026
9.0.23 0 11/10/2026
9.0.22 3 11/04/2026
9.0.21 3 11/06/2026
9.0.20 17 09/12/2026
9.0.19 7 08/11/2026
9.0.18 10 07/17/2026
9.0.17 18 06/25/2026
9.0.16 11 06/25/2026
9.0.15 14 06/25/2026
9.0.14 17 06/25/2026
9.0.13 18 06/25/2026
9.0.12 11 06/25/2026
9.0.11 10 06/25/2026
9.0.10 18 06/25/2026
9.0.9 10 06/26/2026
9.0.8 24 06/26/2026
9.0.7 13 06/26/2026
9.0.6 12 06/26/2026
9.0.5 13 06/26/2026
9.0.4 15 06/26/2026
9.0.3 19 06/26/2026
9.0.2 15 06/26/2026
9.0.1 15 01/24/2025
9.0.0 21 01/24/2025
9.0.0-rc.2.24473.5 22 07/07/2026
9.0.0-rc.1.24431.7 11 07/19/2026
9.0.0-preview.7.24405.7 10 07/07/2026
9.0.0-preview.6.24327.7 8 06/25/2026
9.0.0-preview.5.24306.7 16 06/25/2024
9.0.0-preview.4.24266.19 11 06/25/2026
9.0.0-preview.3.24172.9 11 06/25/2026
9.0.0-preview.2.24128.5 17 06/25/2026
9.0.0-preview.1.24080.9 15 07/08/2026
8.0.1 15 02/05/2026
8.0.0 20 08/12/2024
8.0.0-rc.2.23479.6 17 12/12/2023
8.0.0-rc.1.23419.4 16 01/09/2024
8.0.0-preview.7.23375.6 6 01/09/2024
8.0.0-preview.6.23329.7 13 01/10/2024
8.0.0-preview.5.23280.8 13 01/10/2024
8.0.0-preview.4.23259.5 17 01/10/2024
8.0.0-preview.3.23174.8 17 01/10/2024
8.0.0-preview.2.23128.3 14 01/10/2024
8.0.0-preview.1.23110.8 15 01/10/2024
7.0.0 21 01/04/2024
7.0.0-rc.2.22472.3 13 01/09/2024
7.0.0-rc.1.22426.10 16 01/10/2024
7.0.0-preview.7.22375.6 16 01/10/2024
7.0.0-preview.6.22324.4 10 01/10/2024
7.0.0-preview.5.22301.12 10 01/10/2024
7.0.0-preview.4.22229.4 13 01/10/2024
7.0.0-preview.3.22175.4 18 12/15/2023
7.0.0-preview.2.22152.2 15 01/10/2024
7.0.0-preview.1.22076.8 14 01/10/2024
6.0.2-mauipre.1.22102.15 14 01/10/2024
6.0.2-mauipre.1.22054.8 15 01/10/2024
6.0.1 8 06/26/2026
6.0.0 15 01/08/2024
6.0.0-rc.2.21480.5 13 01/09/2024
6.0.0-rc.1.21451.13 14 01/10/2024
6.0.0-preview.7.21377.19 12 01/10/2024
6.0.0-preview.6.21352.12 13 01/10/2024
6.0.0-preview.5.21301.5 12 01/10/2024
6.0.0-preview.4.21253.7 16 01/10/2024
6.0.0-preview.3.21201.4 14 01/10/2024
6.0.0-preview.2.21154.6 17 01/10/2024
6.0.0-preview.1.21102.12 13 01/10/2024
1.0.2 62 01/05/2023
1.0.1 17 12/24/2023
1.0.0 15 01/08/2024
1.0.0-beta.2 22 01/09/2024
1.0.0-beta.1 15 01/09/2024