title: Schema Evolution sidebar_position: 7 id: schema_evolution 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# supports schema evolution in Compatible(true) mode.
Fory fory = Fory.Builder() .Compatible(true) .Build();
Compatible mode writes type metadata that allows readers and writers with different struct definitions to interoperate.
using Apache.Fory; [ForyObject] public sealed class OneStringField { public string? F1 { get; set; } } [ForyObject] public sealed class TwoStringField { public string F1 { get; set; } = string.Empty; public string F2 { get; set; } = string.Empty; } Fory fory1 = Fory.Builder().Compatible(true).Build(); fory1.Register<OneStringField>(200); Fory fory2 = Fory.Builder().Compatible(true).Build(); fory2.Register<TwoStringField>(200); byte[] payload = fory1.Serialize(new OneStringField { F1 = "hello" }); TwoStringField evolved = fory2.Deserialize<TwoStringField>(payload); // F2 falls back to default value on reader side. System.Diagnostics.Debug.Assert(evolved.F1 == "hello"); System.Diagnostics.Debug.Assert(evolved.F2 == string.Empty);
If you want strict schema identity checks instead of evolution behavior:
Fory strict = Fory.Builder() .Compatible(false) .CheckStructVersion(true) .Build();
This mode throws on schema hash mismatches.
Compatible(true) for independently deployed services.CheckStructVersion(true) when strict matching is required.