Skip to content

Add NativeAOT support - #1

Merged
pableess merged 3 commits into
masterfrom
feature/nativeaot
Sep 14, 2026
Merged

pableess merged 3 commits into
masterfrom
feature/nativeaot

Conversation

@pableess

Copy link
Copy Markdown
Owner

Summary

Makes the library NativeAOT/trim compatible. Fixes the one reflection-based code path and declares AOT support.

Problem

TomlConfigurationFileParser called the reflection-based TomlSerializer.Deserialize<TomlTable>(string) overload, which is annotated [RequiresUnreferencedCode]/[RequiresDynamicCode]. Tomlyn disables reflection-based serialization by default when PublishAot=true, so this would emit IL2026/IL3050 warnings and fail at runtime on NativeAOT.

Changes

  • Add internal source-generated TomlModelSerializerContext with [TomlSerializable(typeof(TomlTable))].
  • Parse via TomlSerializer.Deserialize<TomlTable>(text, TomlModelSerializerContext.Default).
  • Mark the library <IsAotCompatible>true</IsAotCompatible> and bump Tomlyn to 2.10.1.
  • Add a NativeAOT smoke-test project (Tomlyn.Extensions.Configuration.AotTests) that exercises AddTomlFile, AddTomlStream and RemoveUnderscores.
  • Add a CI workflow that runs the tests and publishes/runs the AOT smoke test with -r linux-x64.
  • Document AOT usage in the README (including avoiding reflection-based IConfiguration.Bind).

Verification

  • dotnet build (Release, all TFMs): no IL2026/IL3050 warnings.
  • dotnet test (net10.0): passing.
  • dotnet publish -p:PublishTrimmed=true -r linux-x64 + run: passing (no clang available locally for the full AOT compile; CI installs clang and performs the actual NativeAOT publish/run).

pableess and others added 3 commits September 13, 2026 08:11
Use a source-generated TomlSerializerContext for the internal TomlTable
deserialization instead of the reflection-based overload. Reflection-based
TOML serialization is disabled by default under PublishAot=true, which made
the previous call fail at runtime and emit IL2026/IL3050 warnings.

- Add internal TomlModelSerializerContext with [TomlSerializable(typeof(TomlTable))]
- Parse via TomlSerializer.Deserialize<TomlTable>(text, context)
- Mark the library IsAotCompatible and bump Tomlyn to 2.10.1
- Add a NativeAOT smoke-test project and CI workflow (test + AOT publish/run)
@pableess
pableess marked this pull request as ready for review September 14, 2026 03:28
@pableess
pableess merged commit 89a2e35 into master Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant