C# Setup
Fory C# provides xlang Object Serialization, generated models, and Fory gRPC.
The Apache.Fory NuGet package requires .NET 8 or later and includes both the
serialization library and source generator.
Verify the Toolchain
dotnet --version
Object Serialization
Create a console project and add the released package:
dotnet new console -n ForyExample
cd ForyExample
dotnet add package Apache.Fory --version 1.5.0
Replace Program.cs with:
using Apache.Fory;
[ForyStruct]
public sealed class User
{
public long Id { get; set; }
public string Name { get; set; } = string.Empty;
}
public static class Program
{
public static void Main()
{
Fory fory = Fory.Builder().Build();
fory.Register<User>(1);
byte[] bytes = fory.Serialize(new User { Id = 1, Name = "Alice" });
User decoded = fory.Deserialize<User>(bytes);
Console.WriteLine(decoded.Name);
}
}
dotnet run
C# uses xlang mode. Continue with C# Object Serialization, xlang types, configuration, and schema evolution.
Other Capabilities
- Fory IDL and Compiler generates C# models and registration helpers. See Compiler Getting Started and the C# generated-code guide.
- Fory gRPC uses normal .NET gRPC transports with Fory-encoded messages. See C# gRPC.