dotnet-serialization

Implement AOT-safe serialization with System.Text.Json source generators in .NET.

1|Updated Feb 22, 2026
One-click install
npx skills add https://github.com/rudironsoni/dotnet-agent-harness --skill dotnet-serialization-rudironsoni
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-serialization
Source: https://github.com/rudironsoni/dotnet-agent-harness/tree/main/.rulesync/skills/dotnet-serialization
Command: npx skills add https://github.com/rudironsoni/dotnet-agent-harness --skill dotnet-serialization-rudironsoni

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the complexities of serializing data in .NET applications, particularly for AOT (Ahead-Of-Time) compilation, ensuring performance and compatibility.

Core Features & Use Cases

  • AOT-Safe Serialization: Implements System.Text.Json source generators, Protobuf, and MessagePack for compile-time or AOT-compatible serialization.
  • Performance Optimization: Provides guidance on choosing the right serializer based on performance and payload size needs.
  • Use Case: When building a .NET MAUI application targeting Native AOT, this Skill helps you select and implement the most efficient and compatible serialization strategy to avoid runtime errors and maximize performance.

Quick Start

Use the dotnet-serialization skill to implement AOT-safe JSON serialization using System.Text.Json source generators.

Frequently Asked Questions about dotnet-serialization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make JSON serialization work with .NET Native AOT?

To make JSON serialization work with .NET Native AOT, use System.Text.Json source generators to generate serialization code at compile-time. This avoids reflection at runtime, ensuring your AOT and trimming scenarios remain compatible and performant.

What is the best way to migrate from Newtonsoft.Json to an AOT-compatible serializer?

The best way to migrate from Newtonsoft.Json to an AOT-compatible serializer is adopting System.Text.Json source generators, Protobuf, or MessagePack. These approaches eliminate reflection-based dependencies, enabling efficient data exchange while avoiding runtime errors in Native AOT environments.

Does Protobuf or MessagePack offer better performance for .NET AOT serialization?

Protobuf and MessagePack both offer AOT-compatible serialization for .NET, but performance depends on payload size and structure. Protobuf is ideal for compact binary data exchange, while MessagePack provides fast binary serialization, with tradeoffs in payload efficiency compared to JSON.

Why does reflection-based serialization break in trimmed .NET MAUI applications?

Reflection-based serialization breaks in trimmed .NET MAUI applications because the trimming compiler removes metadata and type information that reflection relies on at runtime. Switching to System.Text.Json source generators, Protobuf, or MessagePack resolves this by shifting serialization logic to compile-time.

Can I use System.Text.Json source generators for compile-time serialization in C#?

Yes, you can use System.Text.Json source generators for compile-time serialization in C#. They generate type-specific serialization code during the build process, removing the need for runtime reflection and ensuring your .NET applications remain AOT-friendly and trim-safe.