System.Memory.Data 10.0.14
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
BinaryDatatype. - 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
|
96 |
|
Azure.Core
This is the implementation of the Azure Client Pipeline
|
94 |
|
Azure.Core
This is the implementation of the Azure Client Pipeline
|
91 |
|
Azure.Core
This is the implementation of the Azure Client Pipeline
|
88 |
|
Azure.Core
This is the implementation of the Azure Client Pipeline
|
86 |
|
Azure.Core
This is the implementation of the Azure Client Pipeline
|
85 |
|
Azure.Core
This is the implementation of the Azure Client Pipeline
|
84 |
|
Azure.Core
This is the implementation of the Azure Client Pipeline
|
83 |
.NET Framework 4.6.2
- System.Text.Json (>= 10.0.14)
- System.Memory (>= 4.6.3)
.NET 8.0
- System.Text.Json (>= 10.0.14)
.NET 9.0
- System.Text.Json (>= 10.0.14)
.NET 10.0
- No dependencies.
.NET Standard 2.0
- System.Text.Json (>= 10.0.14)
- System.Memory (>= 4.6.3)
| Version | Downloads | Last updated |
|---|---|---|
| 11.0.0-rc.3.26522.148 | 2 | 10/28/2026 |
| 11.0.0-rc.2.26504.105 | 5 | 10/17/2026 |
| 11.0.0-rc.1.26425.128 | 14 | 09/11/2026 |
| 11.0.0-preview.7.26381.103 | 22 | 08/11/2026 |
| 11.0.0-preview.6.26359.118 | 27 | 07/18/2026 |
| 11.0.0-preview.5.26302.115 | 35 | 06/11/2026 |
| 11.0.0-preview.4.26230.115 | 34 | 05/13/2026 |
| 11.0.0-preview.3.26207.106 | 41 | 04/23/2026 |
| 11.0.0-preview.2.26159.112 | 45 | 03/11/2026 |
| 11.0.0-preview.1.26104.118 | 42 | 02/12/2026 |
| 10.0.14 | 2 | 10/28/2026 |
| 10.0.13 | 7 | 10/17/2026 |
| 10.0.12 | 13 | 09/11/2026 |
| 10.0.11 | 27 | 08/11/2026 |
| 10.0.10 | 23 | 07/18/2026 |
| 10.0.9 | 27 | 06/11/2026 |
| 10.0.8 | 37 | 05/13/2026 |
| 10.0.7 | 42 | 04/23/2026 |
| 10.0.6 | 41 | 04/23/2026 |
| 10.0.5 | 46 | 03/13/2026 |
| 10.0.4 | 43 | 03/11/2026 |
| 10.0.3 | 47 | 02/12/2026 |
| 10.0.2 | 48 | 01/15/2026 |
| 10.0.1 | 56 | 12/11/2025 |
| 10.0.0 | 57 | 11/13/2025 |
| 10.0.0-rc.2.25502.107 | 63 | 10/16/2025 |
| 10.0.0-rc.1.25451.107 | 69 | 09/18/2025 |
| 10.0.0-preview.7.25380.108 | 65 | 09/05/2025 |
| 10.0.0-preview.6.25358.103 | 64 | 09/05/2025 |
| 10.0.0-preview.5.25277.114 | 69 | 09/05/2025 |
| 10.0.0-preview.4.25258.110 | 65 | 09/05/2025 |
| 10.0.0-preview.3.25171.5 | 69 | 09/05/2025 |
| 10.0.0-preview.2.25163.2 | 74 | 09/05/2025 |
| 10.0.0-preview.1.25080.5 | 69 | 09/05/2025 |
| 9.0.22 | 2 | 10/28/2026 |
| 9.0.21 | 6 | 10/17/2026 |
| 9.0.20 | 12 | 09/11/2026 |
| 9.0.19 | 26 | 08/11/2026 |
| 9.0.18 | 24 | 07/18/2026 |
| 9.0.17 | 34 | 06/11/2026 |
| 9.0.16 | 32 | 05/13/2026 |
| 9.0.15 | 42 | 04/23/2026 |
| 9.0.14 | 43 | 03/11/2026 |
| 9.0.13 | 45 | 02/12/2026 |
| 9.0.12 | 53 | 01/16/2026 |
| 9.0.11 | 58 | 11/13/2025 |
| 9.0.10 | 66 | 10/16/2025 |
| 9.0.9 | 68 | 09/19/2025 |
| 9.0.8 | 67 | 09/05/2025 |
| 9.0.7 | 69 | 09/05/2025 |
| 9.0.6 | 69 | 09/05/2025 |
| 9.0.5 | 70 | 09/05/2025 |
| 9.0.4 | 70 | 09/05/2025 |
| 9.0.3 | 70 | 09/05/2025 |
| 9.0.2 | 70 | 09/05/2025 |
| 9.0.1 | 74 | 09/05/2025 |
| 9.0.0 | 72 | 09/05/2025 |
| 9.0.0-rc.2.24473.5 | 65 | 09/05/2025 |
| 9.0.0-rc.1.24431.7 | 68 | 09/05/2025 |
| 9.0.0-preview.7.24405.7 | 67 | 09/05/2025 |
| 9.0.0-preview.6.24327.7 | 66 | 09/05/2025 |
| 9.0.0-preview.5.24306.7 | 66 | 09/05/2025 |
| 9.0.0-preview.4.24266.19 | 71 | 09/05/2025 |
| 9.0.0-preview.3.24172.9 | 65 | 09/05/2025 |
| 9.0.0-preview.2.24128.5 | 73 | 09/05/2025 |
| 9.0.0-preview.1.24080.9 | 65 | 09/05/2025 |
| 8.0.1 | 73 | 09/05/2025 |
| 8.0.0 | 74 | 09/05/2025 |
| 8.0.0-rc.2.23479.6 | 68 | 09/05/2025 |
| 8.0.0-rc.1.23419.4 | 67 | 09/05/2025 |
| 8.0.0-preview.7.23375.6 | 71 | 09/05/2025 |
| 8.0.0-preview.6.23329.7 | 71 | 09/05/2025 |
| 8.0.0-preview.5.23280.8 | 72 | 09/05/2025 |
| 8.0.0-preview.4.23259.5 | 66 | 09/05/2025 |
| 8.0.0-preview.3.23174.8 | 64 | 09/05/2025 |
| 8.0.0-preview.2.23128.3 | 68 | 09/05/2025 |
| 8.0.0-preview.1.23110.8 | 63 | 09/05/2025 |
| 7.0.0 | 67 | 09/05/2025 |
| 7.0.0-rc.2.22472.3 | 64 | 09/05/2025 |
| 7.0.0-rc.1.22426.10 | 71 | 09/05/2025 |
| 7.0.0-preview.7.22375.6 | 64 | 09/05/2025 |
| 7.0.0-preview.6.22324.4 | 68 | 09/05/2025 |
| 7.0.0-preview.5.22301.12 | 66 | 09/05/2025 |
| 7.0.0-preview.4.22229.4 | 70 | 09/05/2025 |
| 7.0.0-preview.3.22175.4 | 66 | 09/05/2025 |
| 7.0.0-preview.2.22152.2 | 63 | 09/05/2025 |
| 7.0.0-preview.1.22076.8 | 67 | 09/05/2025 |
| 6.0.1 | 67 | 09/05/2025 |
| 6.0.0 | 71 | 09/05/2025 |
| 6.0.0-rc.2.21480.5 | 67 | 09/05/2025 |
| 6.0.0-rc.1.21451.13 | 65 | 09/05/2025 |
| 6.0.0-preview.7.21377.19 | 64 | 09/05/2025 |
| 6.0.0-preview.6.21352.12 | 65 | 09/05/2025 |
| 6.0.0-preview.5.21301.5 | 60 | 09/05/2025 |
| 6.0.0-preview.4.21253.7 | 69 | 09/05/2025 |
| 6.0.0-preview.3.21201.4 | 67 | 09/05/2025 |
| 6.0.0-preview.2.21154.6 | 65 | 09/05/2025 |
| 6.0.0-preview.1.21102.12 | 65 | 09/05/2025 |
| 1.0.2 | 68 | 09/05/2025 |
| 1.0.1 | 69 | 09/05/2025 |
| 1.0.0 | 74 | 09/05/2025 |
| 1.0.0-beta.2 | 69 | 09/05/2025 |
| 1.0.0-beta.1 | 67 | 09/05/2025 |