YHG.FastBF 1.0.1

dotnet add package YHG.FastBF --version 1.0.1
                    
NuGet\Install-Package YHG.FastBF -Version 1.0.1
                    
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="YHG.FastBF" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="YHG.FastBF" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="YHG.FastBF" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add YHG.FastBF --version 1.0.1
                    
#r "nuget: YHG.FastBF, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package YHG.FastBF@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=YHG.FastBF&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=YHG.FastBF&version=1.0.1
                    
Install as a Cake Tool

YHG.FastBF

A high-performance, zero-dependency [MS-NRBF] (BinaryFormatter) serialization and deserialization engine for modern .NET.

NuGet Version License: MIT .NET Version Native AOT


Overview

Starting with .NET 8 and .NET 9, Microsoft marked BinaryFormatter obsolete and completely disabled it by default due to critical remote code execution (RCE) attack vectors.

YHG.FastBF provides a secure, standalone replacement designed to read and write the official Microsoft .NET Remoting Binary Format ([MS-NRBF]) specification. It allows modern applications to serialize and hydrate binary streams, Unity asset structures, and legacy save containers without relying on deprecated framework APIs.


Features

  • Protocol Compliant: Fully implements major wire tags of the [MS-NRBF] specification.
  • Native AOT & Trimming Ready: Fully annotated with [DynamicallyAccessedMembers] to preserve metadata during IL trimming; executes reliably under Native AOT environments.
  • High Throughput: Dynamic compiled Expression trees replace slow runtime reflection with fast member extractors, utilizing internal interpreted execution fallback on Native AOT targets.
  • Cross-Framework Interoperability: Automatically aliases modern System.Private.CoreLib types to legacy mscorlib, Version=4.0.0.0 for backward compatibility with Unity and .NET Framework.
  • Graph Resolution: Multi-pass object tracking resolves circular references and shared object instances safely.
  • Dictionary & Collection Hydration: Native support for generic dictionaries, key-value pair arrays, and primitive lists.
  • Zero External Dependencies: Pure managed code running seamlessly across AnyCPU (x86, x64, ARM64).

Installation

.NET CLI

dotnet add package YHG.FastBF

Package Manager

Install-Package YHG.FastBF

Quick Start

1. Model Definition

You can map legacy or custom property names using attributes:

using System.Collections.Generic;
using YHG.FastBF.Attributes;

[BfType("GameData.PlayerProfile", "Assembly-CSharp")]
public class PlayerProfile : IBfDeserialized
{
    [BfProperty("player_level")]
    public int Level { get; set; }

    public string PlayerName { get; set; } = string.Empty;

    public Dictionary<string, int> Inventory { get; set; } = new();

    [BfIgnore]
    public int EphemeralCache { get; set; }

    public void OnDeserialized()
    {
        // Executed immediately after hydration completes
    }
}

2. Writing (Serialization)

using System.IO;
using System.Collections.Generic;
using YHG.FastBF.Binary;

var profile = new PlayerProfile
{
    Level = 50,
    PlayerName = "Commander",
    Inventory = new Dictionary<string, int>
    {
        { "HealthPotion", 10 },
        { "GoldCoins", 2500 }
    }
};

using (var stream = File.Create("savedata.bin"))
using (var writer = new BfWriter(stream))
{
    writer.WriteRootClass(profile);
}

3. Reading (Deserialization)

using System;
using System.IO;
using YHG.FastBF.Binary;

using (var stream = File.OpenRead("savedata.bin"))
using (var reader = new BfReader(stream))
{
    PlayerProfile profile = reader.ReadRootClass<PlayerProfile>();
    Console.WriteLine($"Loaded: {profile.PlayerName} (Level {profile.Level})");
}

Supported [MS-NRBF] Records

Tag Record Name Status
0x00 SerializedStreamHeader Supported
0x01 ClassWithId Supported
0x04 SystemClassWithMembers Supported
0x05 ClassWithMembersAndTypes Supported
0x06 BinaryObjectString Supported
0x07 BinaryArray Supported
0x08 MemberPrimitiveTyped Supported
0x09 MemberReference Supported
0x0A ObjectNull Supported
0x0B MessageEnd Supported
0x0C BinaryLibrary Supported
0x0D ObjectNullMultiple256 Supported
0x0E ObjectNullMultiple Supported
0x0F ArraySinglePrimitive Supported
0x10 ArraySingleObject Supported
0x11 ArraySingleString Supported

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 44 11/7/2026
1.0.0 54 11/7/2026