BinarySerializer.SourceGeneration 10.2.1

dotnet add package BinarySerializer.SourceGeneration --version 10.2.1
                    
NuGet\Install-Package BinarySerializer.SourceGeneration -Version 10.2.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="BinarySerializer.SourceGeneration" Version="10.2.1">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BinarySerializer.SourceGeneration" Version="10.2.1" />
                    
Directory.Packages.props
<PackageReference Include="BinarySerializer.SourceGeneration">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 BinarySerializer.SourceGeneration --version 10.2.1
                    
#r "nuget: BinarySerializer.SourceGeneration, 10.2.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 BinarySerializer.SourceGeneration@10.2.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=BinarySerializer.SourceGeneration&version=10.2.1
                    
Install as a Cake Addin
#tool nuget:?package=BinarySerializer.SourceGeneration&version=10.2.1
                    
Install as a Cake Tool

BinarySerializer.SourceGeneration

An optional Roslyn source generator for BinarySerializer. It removes the manual rooting step that trimmed and Native AOT applications otherwise need.

BinarySerializer discovers object graphs through reflection at runtime, so the trimmer cannot see which types and members a trimmed or AOT-compiled application serializes. This generator finds those types at compile time and emits code that keeps them.

Installation

Add the package to the project that defines your serialized types, alongside BinarySerializer itself:

dotnet add package BinarySerializer
dotnet add package BinarySerializer.SourceGeneration

The generator runs only at build time. It adds no runtime dependency, and nothing else in your code needs to change.

What it does

The generator collects every type that carries BinarySerializer attributes, everything reachable from their members, subtype, converter and factory types, and closed generic collections such as List<MyItem>. For those types it emits a module initializer that:

  • roots the types for trimming and AOT compilation, so no TrimmerRoots.xml or [DynamicDependency] is needed for them;
  • registers compiled member accessors and parameterless constructor factories, so building the type graph needs neither reflection nor dynamic code generation.

Serialized bytes are identical with or without the generator.

Things to know

  • Types without BinarySerializer attributes. A root type that has no BinarySerializer attributes on it or its members is not discovered automatically. Mark it with [BinarySerializerRoot].
  • Types the generated code cannot reference. Private or protected nested types and C# file types are skipped. They still serialize through the reflection path, but the generator does not root them, so root them manually in a trimmed or AOT-compiled application.
  • Version requirement. The generator needs BinarySerializer 10.2.0 or later. With an older BinarySerializer it generates nothing and reports warning BSG001.

Documentation

See the AOT and Trimming section of the BinarySerializer README for the full guide, including manual rooting without the generator.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has 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
10.2.1 42 11/12/2026
10.2.0 48 11/12/2026