NetBinSerializer 1.0.2

.NET Standard 2.0
dotnet add package NetBinSerializer --version 1.0.2
NuGet\Install-Package NetBinSerializer -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetBinSerializer" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetBinSerializer --version 1.0.2
#r "nuget: NetBinSerializer, 1.0.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install NetBinSerializer as a Cake Addin
#addin nuget:?package=NetBinSerializer&version=1.0.2

// Install NetBinSerializer as a Cake Tool
#tool nuget:?package=NetBinSerializer&version=1.0.2


C# types serialization library


  • minimum result bytes array size (without compressing)
  • program and version independence (but it's unsafe (without classes fields coincidence control))
  • base for serialization methods auto builders
  • opportunity to save serialization/deserialization type methods and use it
  • using reflection only for type serialization methods building


  • serialization classes and structures extension isn't allowed. I.e. if class Cat : Animal will be passed with animal type, it will be serialized as an Animal
  • NetBinSerializer can't normal serialize/deserialize types, which use system pointers/descriptors and other resources
  • you should know, which fields are in serialized class/structure


NetBinSerialization library has two serialization classes
SerializeStream - low level serialization object to serialize base types
Serializer - high level serialization static class with serialization methods caching, picking and building for difficult types

ISerializable - interface with writeToStream and readToStream methods. If a class or structure implements this interface, serialization and deserialization will be complete by these methods call (deserialization works without constructor call!).
ISerializationMethodsBuilder - interface for high level serialize/deserialize custom methods builder class (implement getSerializationMethods for type serialization methods build)
As methods builder you can use SMAB library.

SerializationMethodsBase - object, that provides methods serialize(SerializeStream stream, object obj) and object deserialize(SerializeStream stream). Serializer class contains cached Dictionary of <Type, ISerializationMethods>.


Stream for objects serialization/deserialization

  • for serialization create SerializeStream by new SerializeStream()
  • for deserialization create SerializeStream by new SerializeStream(byte[] bytes)

Supported main types: Int64, Int32, Int16, SByte, UInt64, UInt32, UInt16, Byte, Float, Double, String, bytes array, Serializable

  • to write base type in bytes use void Write+[var_type]([var_type]) or void Write([var_type]) overloaded method
  • to read base type in bytes use [var_type] Read+[var_type]()
  • you can write objects by void WriteUnknown(object), but it's no reason to use this method. You should always know serializable/deserializable object's type

Also SerializeStream can work with other Arrays and Collections types, but it's better to use Serializer.serialize and Serializer.deserialize methods for difficult types Write and read other types methods:

  • void WriteArray(Array) / Array ReadArray(Type) with generic analogs
  • void WriteCollectionObject(object) / object ReadCollectionObject(Type)
  • void WriteObject(object) / object ReadObject() for difficultObject's (by using BinaryFormatter)


High level serialization class, with supports caching, serialize/deserialize methods save, custom methods builders It's better to use this for difficult types, which aren't SerializeStream main types (also it's better for arrays and collections)

  • bool IsCached(Type) returns true if type's serialization methods are in cache
  • bool GetCached(Type, out ISerializationMethods methods) returns true and methods = serialization methods container if type's serialization methods are in cache else false
  • bool Cache(SerializationMethods.SerializeMethod, SerializationMethods.DeserializeMethod, Type) adds serialize and deserialize methods in cache, returns false, if methods for type are already in cache.
  • bool Cache(this ISerializationMethods, Type) cache function for methods in ISerializationMethods shell
Prebuild serialization methods
  • bool BuildAndCacheIntegrated(Type) (builds and caches type serialization methods with integrated SimpleSerializationMethodsBuilder (only for arrays and collections)) returns true if success
  • bool BuildAndCache(Type) builds and caches type serialization methods with custom serializationMethodsBuilder
  • SerializeSafe/DeserializeSafe and generics analogs returns true, if obejct was successfully serialized/deserialized
  • Serialize/Deserialize if serialization/deserialization fail occured, thrwos SerializationException Also Serializer methods has this SerializeStream arg, and because you can write stream.serialize(myObject, typeof(MyObject))

SerializationContext is optimization class, that solves some references problem (inclusive references cycles in the serialize tree) and approves null values


Example code for low and hight levels serialization/deserialization

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on NetBinSerializer:

Package Downloads

C# library for auto build serialize and deserialize to byte array methods for given type (based on NetBinSerializer).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 301 7/23/2021
1.0.1 253 5/16/2021
1.0.0 196 5/13/2021