SharpYaml 3 is a breaking-change release aligned with modern .NET serialization patterns.
net8.0, net10.0, and netstandard2.0.Old:
var serializer = new Serializer(new SerializerSettings());
var yaml = serializer.Serialize(value);
var model = serializer.Deserialize<MyType>(yaml);
New:
var options = new YamlSerializerOptions();
var yaml = YamlSerializer.Serialize(value, options);
var model = YamlSerializer.Deserialize<MyType>(yaml, options);
The following legacy APIs are no longer public in v3:
SerializerSerializerSettingsSerializerContextIYamlSerializable / IYamlSerializableFactoryUse these replacements:
YamlMemberAttribute -> YamlPropertyNameAttribute and/or YamlPropertyOrderAttributeYamlIgnoreAttribute -> YamlIgnoreAttribute (kept)YamlIncludeAttribute or JsonIncludeAttributeJsonPolymorphicAttribute, JsonDerivedTypeAttributeYamlPolymorphicAttribute, YamlDerivedTypeAttributeRemoved legacy attributes:
YamlMemberAttributeYamlTagAttributeYamlStyleAttributeYamlRemapAttributev3 supports key System.Text.Json.Serialization attributes directly for member mapping:
JsonPropertyNameJsonPropertyOrderJsonIgnoreJsonIncludeYAML-specific attributes take precedence when both are present.
Reflection fallback is available by default and can be disabled:
AppContext.SetSwitch("SharpYaml.YamlSerializer.IsReflectionEnabledByDefault", false);
When disabled, POCO/object mapping requires metadata via YamlSerializerOptions.TypeInfoResolver (typically from a YamlSerializerContext).
Built-in primitives and untyped containers remain supported without reflection.
Create a context class and declare serializable roots with JsonSerializable:
using System.Text.Json.Serialization;
using SharpYaml.Serialization;
[JsonSerializable(typeof(MyType))]
internal partial class MyYamlContext : YamlSerializerContext
{
}
Then consume typed metadata:
var context = MyYamlContext.Default;
var yaml = YamlSerializer.Serialize(value, context.MyType);
var model = YamlSerializer.Deserialize(yaml, context.MyType);
SharpYaml.Syntax for lossless roundtrip and source span tooling.YamlSerializer maps to .NET objects and does not preserve formatting/comments.