title: C# Serialization Guide sidebar_position: 0 id: serialization_index license: | Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Apache Fory™ C# is a high-performance, cross-language serialization runtime for .NET. It provides object graph serialization, schema evolution, generic object payload support, and a thread-safe wrapper for concurrent workloads.
[ForyObject] typesThreadSafeFory) for multi-threaded servicesReference the single Apache.Fory package. It includes the runtime and the source generator for [ForyObject] types.
<ItemGroup> <PackageReference Include="Apache.Fory" Version="0.16.0" /> </ItemGroup>
using Apache.Fory; [ForyObject] public sealed class User { public long Id { get; set; } public string Name { get; set; } = string.Empty; public string? Email { get; set; } } Fory fory = Fory.Builder().Build(); fory.Register<User>(1); User user = new() { Id = 1, Name = "Alice", Email = "alice@example.com", }; byte[] payload = fory.Serialize(user); User decoded = fory.Deserialize<User>(payload);
Serialize<T>(in T value) / Deserialize<T>(...)Serialize<object?>(...) / Deserialize<object?>(...) for dynamic payloadsRegister<T>(uint typeId) and namespace/name registration APIsRegister<T, TSerializer>(...) for custom serializers| Topic | Description |
|---|---|
| Configuration | Builder options and runtime modes |
| Basic Serialization | Typed and dynamic serialization APIs |
| Type Registration | Registering user types and custom serializers |
| Custom Serializers | Implementing Serializer<T> |
| Field Configuration | [Field] attribute and integer encoding options |
| References | Shared/circular reference handling |
| Schema Evolution | Compatible mode behavior |
| Cross-Language | Interoperability guidance |
| Supported Types | Built-in and generated type support |
| Thread Safety | Fory vs ThreadSafeFory usage |
| Troubleshooting | Common errors and debugging steps |