---
title: "Migrate from SharpYaml to OneYaml"
url: https://recursiveai.org/oneyaml/articles/migrate-from-sharpyaml/
description: "Swap the package and imports for common SharpYaml 3 serializer calls. Port to native OneYaml APIs if you use converters or generated contexts."
date: 2026-11-25
author: Recursive AI
---

# Migrate from SharpYaml to OneYaml

Swap the package and imports for common SharpYaml 3 serializer calls. Port to native OneYaml APIs if you use converters or generated contexts.

November 25, 2026 · Recursive AI

[OneYaml for C#](https://recursiveai.org/oneyaml/csharp/), a YAML parser and serializer for .NET, is free and open source from Recursive AI, under [MIT or Apache-2.0](https://github.com/recursive-ai-oss/oneyaml-csharp/blob/7818048c4be434333767c47d66176fc626d1da8e/README.md#license). [NuGet](https://www.nuget.org/packages/OneYaml.Compat.SharpYaml/1.2.1) · [GitHub](https://github.com/recursive-ai-oss/oneyaml-csharp/tree/v1.2.1)

`dotnet add package OneYaml.Compat.SharpYaml --version 1.2.1`

*Program.cs · OneYaml adapter 1.2.1 · .NET 10*

```
using System.Text.Json;
using OneYaml.Compat.SharpYaml;
 
var options = new YamlSerializerOptions
{
    PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
var job = YamlSerializer.Deserialize<Job>("name: backup\nretries: 2\n", options)!;
Console.Write(YamlSerializer.Serialize(job with { Retries = 3 }, options));
 
record Job(string Name, int Retries);
```

*Output*

```
name: backup
retries: 3
```

## Swap the package and imports

Use a separate .NET 10 console project for each example. To switch an existing project, remove its direct `SharpYaml` reference with `dotnet remove package SharpYaml`, then run the adapter install command above. If another library exposes SharpYaml types, it still needs the original package: the adapter’s types are not interchangeable with them.

The example was tested against [SharpYaml 3.14.0](https://www.nuget.org/packages/SharpYaml/3.14.0), the baseline in the [OneYaml compatibility notes](https://github.com/recursive-ai-oss/oneyaml-csharp/blob/7818048c4be434333767c47d66176fc626d1da8e/docs/compat/sharpyaml.md#what-is-covered). This is not a migration from SharpYaml 2’s API; see [SharpYaml’s v2-to-v3 guide](https://xoofx.github.io/SharpYaml/migration/) if that’s where you’re starting.

| SharpYaml 3.14.0 | OneYaml adapter 1.2.1 |
|---|---|
| `using SharpYaml;` | `using OneYaml.Compat.SharpYaml;` |
| `using SharpYaml.Serialization;` | `using OneYaml.Compat.SharpYaml.Serialization;` |
| `YamlSerializer.Serialize`, `Deserialize`, `TryDeserialize` | Same names for supported serializer calls. The example keeps the record, generic call, and camel-case naming policy. |
| Attributes such as `YamlPropertyName`, `YamlIgnore`, and `YamlRequired` | Same names in the adapter’s `Serialization` namespace. Use the adapter types on your models. |
| `YamlException`, `SyntaxErrorException`, `SemanticErrorException` | Types exist, but the adapter throws `SyntaxErrorException` for syntax errors and `YamlException` for other YAML errors. Don’t rely on a `SemanticErrorException` catch alone. |

## Check what compiles and what runs

The adapter has no custom converters, `IYamlOn*` hooks, serializer polymorphism or extension data, or `Model` and `Syntax` APIs. A context declaration can compile without generating `Ctx.Default` or typed metadata properties. Check the [full list of omissions](https://github.com/recursive-ai-oss/oneyaml-csharp/blob/7818048c4be434333767c47d66176fc626d1da8e/docs/compat/sharpyaml.md#what-is-left-out) before swapping packages.

Other settings compile but throw `NotSupportedException` at first use. Those include a non-Core schema, `DictionaryKeyPolicy`, and `DuplicateKeyHandling` set to `LastWins` or `FirstWins`. For example:

*Program.cs · OneYaml adapter 1.2.1 · .NET 10*

```
using OneYaml.Compat.SharpYaml;
using OneYaml.Compat.SharpYaml.Serialization;
 
var options = new YamlSerializerOptions
{
    DuplicateKeyHandling = YamlDuplicateKeyHandling.LastWins
};
try
{
    YamlSerializer.Deserialize<object>("retries: 2\nretries: 3\n", options);
}
catch (NotSupportedException error)
{
    Console.WriteLine(error.Message);
}
```

*Output*

```
DuplicateKeyHandling is not supported by OneYaml.Compat.SharpYaml. Leave it at its default value. See docs/compat/sharpyaml.md for what is and what is not covered.
```

Run your own fixtures for duplicate keys, numeric overflow, and any byte-for-byte YAML snapshots. The adapter writes whole floats with a fraction and can quote YAML 1.1 look-alikes such as `on`. For input you don’t control, review [OneYaml’s read limits](https://recursiveai.org/oneyaml/csharp/docs/limits/), including the adapter-only `Limits` option.

## Move to the native OneYaml API when the adapter doesn’t fit

For new code, start with the [native serializer](https://recursiveai.org/oneyaml/csharp/docs/serializer/). Port converters and generated contexts rather than carrying their SharpYaml types over. If you’re editing an existing file rather than serializing a model, use `YamlDocument` to keep its comments. Here the inline comment stays in place when the retry count changes:

`dotnet add package OneYaml --version 1.2.1`

*Program.cs · OneYaml 1.2.1 · .NET 10*

```
using OneYaml;
 
using var doc = YamlDocument.Parse("name: backup\nretries: 2  # retry budget\n");
doc.Root["retries"] = 3;
Console.Write(doc);
```

*Output*

```
name: backup
retries: 3  # retry budget
```

See the [OneYaml migration guide](https://recursiveai.org/oneyaml/csharp/docs/migrate-sharpyaml/) for native serializer mappings and the [editing guide](https://recursiveai.org/oneyaml/csharp/docs/editing/) for document operations.
