Configuration
This page covers ForyBuilder options and default configuration values for Apache Fory™ C#.
Config is an immutable runtime snapshot created by ForyBuilder.
Build a Runtime
using Apache.Fory;
Fory fory = Fory.Builder().Build();
ThreadSafeFory threadSafe = Fory.Builder().BuildThreadSafe();
Default Configuration
Fory.Builder().Build() uses:
| Option | Default | Description |
|---|---|---|
TrackRef | false | Reference tracking disabled |
Compatible | true | Compatible schema-evolution metadata enabled |
CheckStructVersion | false | Struct schema hash checks disabled |
MaxDepth | 20 | Max dynamic nesting depth |
Builder Options
C# always uses xlang-compatible framing, so ForyBuilder does not expose a mode toggle.
TrackRef(bool enabled = false)
Enables reference tracking for shared/circular object graphs.
Fory fory = Fory.Builder()
.TrackRef(true)
.Build();
Compatible(bool enabled = false)
Enables schema evolution mode. C# uses the xlang wire format only, so compatible mode is enabled by
default for independently deployed peers. Passing false opts into schema-consistent payloads when
every writer and reader uses the same schema.
Fory fory = Fory.Builder()
.Compatible(true)
.Build();
CheckStructVersion(bool enabled = false)
Enables strict schema hash validation for generated struct serializers.
Fory fory = Fory.Builder()
.CheckStructVersion(true)
.Build();
MaxDepth(int value)
Sets max nesting depth for dynamic object graphs.
Fory fory = Fory.Builder()
.MaxDepth(32)
.Build();
value must be greater than 0.
Common Configurations
Schema-consistent service
Fory fory = Fory.Builder()
.TrackRef(false)
.Compatible(false)
.Build();
Compatible cross-language service
Fory fory = Fory.Builder()
.TrackRef(true)
.Build();
Thread-safe service instance
ThreadSafeFory fory = Fory.Builder()
.Compatible(true)
.TrackRef(true)
.BuildThreadSafe();
Security
Security-related configuration:
- Register only the expected types before deserializing untrusted payloads.
- Use
CheckStructVersion(true)withCompatible(false)when exact schema matching is required. - Set
MaxDepth(...)to reject unexpectedly deep dynamic object graphs. - Prefer generated or registered concrete models over broad dynamic fields for untrusted input.