Fluent.Unions.MessagePack 1.1.0

dotnet add package Fluent.Unions.MessagePack --version 1.1.0
                    
NuGet\Install-Package Fluent.Unions.MessagePack -Version 1.1.0
                    
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="Fluent.Unions.MessagePack" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fluent.Unions.MessagePack" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Fluent.Unions.MessagePack" />
                    
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 Fluent.Unions.MessagePack --version 1.1.0
                    
#r "nuget: Fluent.Unions.MessagePack, 1.1.0"
                    
#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 Fluent.Unions.MessagePack@1.1.0
                    
#: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=Fluent.Unions.MessagePack&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Fluent.Unions.MessagePack&version=1.1.0
                    
Install as a Cake Tool

Fluent.Unions

Fluent.Unions.MessagePack

NuGet Downloads Publish Documentation

A MessagePack-CSharp (MIT) formatter and resolver for Option<T>. An option is written as its value, or as nil when it holds none. Results refuse to serialize, like in the System.Text.Json support of Fluent.Unions.

Installation

dotnet add package Fluent.Unions.MessagePack

Usage

using MessagePack;
using Fluent.Unions;
using Fluent.Unions.MessagePack;

var options = MessagePackSerializerOptions.Standard.WithFluentUnions();

byte[] bytes = MessagePackSerializer.Serialize<Option<int>>(7, options);                 // 7
byte[] none = MessagePackSerializer.Serialize<Option<int>>(Option.None, options);        // nil
Option<int> back = MessagePackSerializer.Deserialize<Option<int>>(bytes, options);       // 7

WithFluentUnions() puts UnionsResolver in front of the resolver the options already use.

Source-generated formatters

The MessagePack source generator cannot generate code for a member of type Option<T>: it treats the union as a type to generate a formatter for, and the generated resolver does not compile (CS0426). Choose one of these on the containing type:

[MessagePackObject]
public class Customer
{
    [Key(0)]
    [MessagePackFormatter(typeof(OptionFormatter<string>))]
    public Option<string> Nickname { get; set; }
}

[MessagePackObject(SuppressSourceGeneration = true)]
public class Scoreboard
{
    [Key(0)]
    public Option<int>[] Scores { get; set; } = [];
}

The first names the formatter per member and keeps the source generator. The second falls back to the reflection-based resolver, which finds UnionsResolver through the options.

Documentation

Rules

  • Nil is None. Nil reads as None, and a formatter that returns null also gives None. null never becomes a value.
  • Results throw. Result, Result<T> and every result type you declare with [FluentResult<TError>] throw NotSupportedException, wrapped by MessagePack in a MessagePackSerializationException, when writing and when reading. An error would expose exception details such as the stack trace. Convert the result first.
  • Reflection. UnionsResolver creates formatters with MakeGenericType, so it does not work in trimmed or native AOT apps. Register OptionFormatter<T> yourself there.
  • Your own unions are not covered by this package.
Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.1.0 96 11/22/2026
1.0.0 98 11/21/2026
0.3.0 97 11/20/2026