Tomlyn 1.2.0

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

Tomlyn ci Coverage Status NuGet

<img align="right" width="256px" height="256px" src="img/Tomlyn.png">

Tomlyn is a high-performance .NET TOML 1.1 parser, round-trippable syntax tree, and System.Text.Json-style object serializer - NativeAOT ready.

<img src="https://xoofx.github.io/SharpYaml/img/SharpYaml.png" alt="SharpYaml" height="32" style="vertical-align: text-bottom; margin-right: .45rem;" /> Looking for YAML support? Check out SharpYaml.

Note: Tomlyn v1 is a major redesign with breaking changes from earlier versions. It uses a System.Text.Json-style API with TomlSerializer, TomlSerializerOptions, and resolver-based metadata (ITomlTypeInfoResolver). See the migration guide for details.

✨ Features

  • System.Text.Json-style API: familiar surface with TomlSerializer, TomlSerializerOptions, TomlTypeInfo<T>
  • TOML 1.1.0 only: Tomlyn v1 targets TOML 1.1.0 and does not support TOML 1.0
  • Source generation: NativeAOT / trimming friendly via TomlSerializerContext and [TomlSerializable] roots
  • System.Text.Json attribute interop: reuse [JsonPropertyName], [JsonIgnore], [JsonRequired], [JsonConstructor], polymorphism attributes
  • Allocation-free parsing pipeline: incremental TomlLexer β†’ TomlParser with precise spans for errors
  • Low-level access: full lexer/parser API plus a lossless, trivia-preserving syntax tree (SyntaxParser β†’ DocumentSyntax)
  • Reflection control: reflection-based POCO mapping is available, but can be disabled for NativeAOT via a feature switch / MSBuild property

πŸ“ Requirements

Tomlyn targets net8.0, net10.0, and netstandard2.0.

  • Consuming the NuGet package works on any runtime that supports netstandard2.0 (including .NET Framework) or modern .NET (net8.0+).
  • Building Tomlyn from source requires the .NET 10 SDK.

πŸ“¦ Install

dotnet add package Tomlyn

Tomlyn ships the source generator in-package (analyzers/dotnet/cs) - no extra package needed.

πŸš€ Quick Start

using Tomlyn;

// Serialize
var toml = TomlSerializer.Serialize(new { Name = "Ada", Age = 37 });

// Deserialize
var person = TomlSerializer.Deserialize<Person>(toml);

Untyped model (TomlTable)

using Tomlyn;
using Tomlyn.Model;

var toml = @"global = ""this is a string""
# This is a comment of a table
[my_table]
key = 1 # Comment a key
value = true
list = [4, 5, 6]
";

var model = TomlSerializer.Deserialize<TomlTable>(toml)!;
var global = (string)model["global"]!;

Console.WriteLine(global);
Console.WriteLine(TomlSerializer.Serialize(model));

Options

using System.Text.Json;
using Tomlyn;

var options = new TomlSerializerOptions
{
    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
    WriteIndented = true,
    IndentSize = 4,
    MaxDepth = 64,
    DefaultIgnoreCondition = TomlIgnoreCondition.WhenWritingNull,
};

var toml = TomlSerializer.Serialize(config, options);
var model = TomlSerializer.Deserialize<MyConfig>(toml, options);

By default, PropertyNamingPolicy is null, meaning CLR member names are used as-is for TOML mapping keys (same default as System.Text.Json). MaxDepth = 0 uses the built-in default of 64.

Source Generation

using System.Text.Json.Serialization;
using Tomlyn.Serialization;

public sealed class MyConfig
{
    public string? Global { get; set; }
}

[TomlSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
[TomlSerializable(typeof(MyConfig))]
internal partial class MyTomlContext : TomlSerializerContext
{
}

var config = TomlSerializer.Deserialize(toml, MyTomlContext.Default.MyConfig);
var tomlOut = TomlSerializer.Serialize(config, MyTomlContext.Default.MyConfig);

Reflection Control

Reflection fallback can be disabled globally before first serializer use:

AppContext.SetSwitch("Tomlyn.TomlSerializer.IsReflectionEnabledByDefault", false);

When publishing with NativeAOT (PublishAot=true), the Tomlyn NuGet package disables reflection-based serialization by default. You can override the default by setting the following MSBuild property in your app project:

<PropertyGroup>
  <TomlynIsReflectionEnabledByDefault>true</TomlynIsReflectionEnabledByDefault>
</PropertyGroup>

πŸ“– Documentation

πŸͺͺ License

This software is released under the BSD-Clause 2 license.

πŸ€— Author

Alexandre Mutel aka xoofx.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (53)

Showing the top 5 NuGet packages that depend on Tomlyn:

Package Downloads
ROFSDB

Package Description

DafnyCore

Package Description

Ikon.Common.Core

Ikon Common Core is a .NET library that provides common functionality for the Ikon AI C# SDK

CounterStrikeSharp.API

Official server side runtime assembly for CounterStrikeSharp

SwiftlyS2.CS2

Package Description

GitHub repositories (24)

Showing the top 20 popular GitHub repositories that depend on Tomlyn:

Repository Stars
dafny-lang/dafny
Dafny is a verification-aware programming language
roflmuffin/CounterStrikeSharp
CounterStrikeSharp allows you to write server plugins in C# for Counter-Strike 2/Source2/CS2
StateSmith/StateSmith
A state machine code generation tool suitable for bare metal, embedded and more.
microsoft/Oryx
Build your repo automatically.
xenia-manager/xenia-manager
Xenia Manager is a tool that tries to make using Xenia Emulator easier.
xoofx/dotnet-releaser
Easily build, run tests and coverage, cross-compile, package and publish your .NET library or application to NuGet and GitHub.
rwmt/Multiplayer
Zetrith's Multiplayer mod for RimWorld
flipswitchingmonkey/FlexASIO_GUI
Simple configuration GUI for FlexASIO
exercism/csharp
Exercism exercises in C#.
h4lfheart/FortnitePorting
The quickest and most efficient way to extract assets from Fortnite
imazen/imageflow-server
A super-fast image server to speed up your site - deploy as a microservice, serverless, or embeddable.
LiuYunPlayer/TuneLab
Doddler/RagnarokRebuildTcp
Ragnarok-like server + client
ohhsodead/arisen-studio
Browse, Download and Install Mods for PlayStation 3 & Xbox 360
ItsDeltin/Overwatch-Script-To-Workshop
Converts scripts to Overwatch workshops.
TekkaGB/DivaModManager
PCL-Community/PCL.Neo
δΈ€δΈͺ用 Avalonia ι‡ε†™ηš„ PCL
yiikooo/Aurelio
yiikooo/YMCL.Avalonia
Yu Minecraft Launcher · YMCL !
toonymak1993/GameConsoleMode
Version Downloads Last Updated
1.2.0 1,592 3/11/2026
1.1.1 2,874 3/8/2026
1.1.0 264 3/6/2026
1.0.0 1,311 3/4/2026
0.20.0 38,724 1/24/2026
0.19.0 348,680 3/11/2025
0.18.0 90,671 12/22/2024
0.17.0 1,032,084 11/23/2023
0.16.2 724,944 12/22/2022
0.16.1 39,006 10/27/2022
0.16.0 27,083 10/20/2022
0.15.1 45,397 10/13/2022
0.15.0 255,662 7/1/2022
0.14.4 3,735 6/21/2022
0.14.3 578,306 5/9/2022
0.14.2 42,327 4/21/2022
0.14.1 1,888 4/3/2022
0.14.0 5,931 3/10/2022
0.13.1 1,734 3/6/2022
0.13.0 1,687 3/5/2022
Loading failed