System.Memory.Data 11.0.0

About

System.Memory.Data introduces the BinaryData type, a lightweight abstraction for a byte payload. It makes it easy to convert between string, bytes, and stream.

This abstraction can simplify the API surface by exposing a single type instead of numerous overloads or properties. The BinaryData type handles data ownership efficiently, wrapping passed-in bytes when using byte[] or ReadOnlyMemory<byte> constructors or methods, and managing data as bytes when dealing with streams, strings, or rich model types serialized as JSON.

Key Features

  • Lightweight abstraction for byte payload via BinaryData type.
  • Convenient helper methods for common conversions among string, bytes, and stream.
  • Efficient data ownership handling.

How to Use

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>();

Main Types

The main types provided by this library are:

  • System.BinaryData

Additional Documentation

Feedback & Contributing

System.Memory.Data 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.Memory.Data.

Packages Downloads
Azure.Core
This is the implementation of the Azure Client Pipeline
193
Azure.Core
This is the implementation of the Azure Client Pipeline
181
Azure.Core
This is the implementation of the Azure Client Pipeline
176
Azure.Core
This is the implementation of the Azure Client Pipeline
175
Azure.Core
This is the implementation of the Azure Client Pipeline
173
Azure.Core
This is the implementation of the Azure Client Pipeline
170
Azure.Core
This is the implementation of the Azure Client Pipeline
168
Azure.Core
This is the implementation of the Azure Client Pipeline
166
Azure.Core
This is the implementation of the Azure Client Pipeline
165
Azure.Core
This is the implementation of the Azure Client Pipeline
163
System.ClientModel
Contains building blocks for clients that call cloud services.
162
Azure.Core
This is the implementation of the Azure Client Pipeline
162
Azure.Core
This is the implementation of the Azure Client Pipeline
159
Azure.Core
This is the implementation of the Azure Client Pipeline
157
System.ClientModel
Contains building blocks for clients that call cloud services.
153
Azure.Core
This is the implementation of the Azure Client Pipeline
152

.NET 10.0

.NET 11.0

  • No dependencies.

.NET Framework 4.6.2

.NET Standard 2.0

Version Downloads Last updated
11.0.0 5 11/10/2026
11.0.0-rc.3.26522.148 16 10/26/2026
11.0.0-rc.2.26504.105 17 10/14/2026
11.0.0-rc.1.26425.128 24 9/10/2026
11.0.0-preview.7.26381.103 23 8/13/2026
11.0.0-preview.6.26359.118 25 7/14/2026
11.0.0-preview.5.26302.115 31 6/11/2026
11.0.0-preview.4.26230.115 38 5/12/2026
11.0.0-preview.3.26207.106 34 5/4/2026
11.0.0-preview.2.26159.112 42 3/12/2026
11.0.0-preview.1.26104.118 44 2/11/2026
10.0.15 5 11/10/2026
10.0.14 14 10/26/2026
10.0.13 20 10/14/2026
10.0.12 31 9/10/2026
10.0.11 31 8/13/2026
10.0.10 41 7/14/2026
10.0.9 41 6/11/2026
10.0.8 39 5/12/2026
10.0.7 48 5/4/2026
10.0.6 42 5/4/2026
10.0.5 38 3/16/2026
10.0.4 38 3/12/2026
10.0.3 59 2/11/2026
10.0.2 43 1/15/2026
10.0.1 60 12/11/2025
10.0.0 71 11/12/2025
10.0.0-rc.2.25502.107 84 10/16/2025
10.0.0-rc.1.25451.107 84 9/11/2025
10.0.0-preview.7.25380.108 77 8/14/2025
10.0.0-preview.6.25358.103 82 7/20/2025
10.0.0-preview.5.25277.114 88 6/8/2025
10.0.0-preview.4.25258.110 98 5/15/2025
10.0.0-preview.3.25171.5 103 4/11/2025
10.0.0-preview.2.25163.2 104 3/26/2025
10.0.0-preview.1.25080.5 98 2/27/2025
9.0.23 4 11/10/2026
9.0.22 15 10/26/2026
9.0.21 14 10/14/2026
9.0.20 25 9/9/2026
9.0.19 32 8/14/2026
9.0.18 25 7/14/2026
9.0.17 43 6/11/2026
9.0.16 36 5/12/2026
9.0.15 39 5/3/2026
9.0.14 47 3/12/2026
9.0.13 43 2/11/2026
9.0.12 42 1/15/2026
9.0.11 66 11/11/2025
9.0.10 79 10/17/2025
9.0.9 100 9/11/2025
9.0.8 89 8/6/2025
9.0.7 101 7/14/2025
9.0.6 92 6/13/2025
9.0.5 119 5/16/2025
9.0.4 123 4/11/2025
9.0.3 124 3/13/2025
9.0.2 124 2/14/2025
9.0.1 134 1/28/2025
9.0.0 132 11/14/2024
9.0.0-rc.2.24473.5 120 10/22/2024
9.0.0-rc.1.24431.7 111 9/12/2024
9.0.0-preview.7.24405.7 127 8/19/2024
9.0.0-preview.6.24327.7 124 7/10/2024
9.0.0-preview.5.24306.7 141 6/20/2024
9.0.0-preview.4.24266.19 133 6/5/2024
9.0.0-preview.3.24172.9 129 5/7/2024
9.0.0-preview.2.24128.5 127 3/18/2024
9.0.0-preview.1.24080.9 127 2/28/2024
8.0.1 139 10/26/2024
8.0.0 143 11/16/2023
8.0.0-rc.2.23479.6 155 10/23/2023
8.0.0-rc.1.23419.4 138 9/15/2023
8.0.0-preview.7.23375.6 145 8/22/2023
8.0.0-preview.6.23329.7 139 8/4/2023
8.0.0-preview.5.23280.8 130 8/2/2023
8.0.0-preview.4.23259.5 140 5/20/2023
8.0.0-preview.3.23174.8 131 5/20/2023
8.0.0-preview.2.23128.3 137 5/20/2023
8.0.0-preview.1.23110.8 149 2/26/2023
7.0.0 153 12/7/2022
7.0.0-rc.2.22472.3 142 12/7/2022
7.0.0-rc.1.22426.10 141 9/15/2022
7.0.0-preview.7.22375.6 143 9/7/2022
7.0.0-preview.6.22324.4 136 9/19/2022
7.0.0-preview.5.22301.12 135 7/1/2022
7.0.0-preview.4.22229.4 134 7/1/2022
7.0.0-preview.3.22175.4 163 7/1/2022
7.0.0-preview.2.22152.2 135 7/1/2022
7.0.0-preview.1.22076.8 151 7/1/2022
6.0.2-mauipre.1.22102.15 144 7/1/2022
6.0.2-mauipre.1.22054.8 138 7/1/2022
6.0.1 126 11/14/2024
6.0.0 185 7/1/2022
6.0.0-rc.2.21480.5 134 7/1/2022
6.0.0-rc.1.21451.13 149 7/1/2022
6.0.0-preview.7.21377.19 140 7/1/2022
6.0.0-preview.6.21352.12 141 7/1/2022
6.0.0-preview.5.21301.5 137 7/1/2022
6.0.0-preview.4.21253.7 141 7/1/2022
6.0.0-preview.3.21201.4 149 7/1/2022
6.0.0-preview.2.21154.6 145 7/1/2022
6.0.0-preview.1.21102.12 136 7/1/2022
1.0.2 149 7/1/2022
1.0.1 164 7/1/2022
1.0.0 161 7/1/2022
1.0.0-beta.2 148 7/1/2022
1.0.0-beta.1 155 7/1/2022