---
title: "Migrate from DiffPlex to OneDiff in C#"
url: https://recursiveai.org/onediff/articles/migrate-from-diffplex/
description: "Replace DiffPlex’s inline builder with Diff.Lines, then port the result handling, side-by-side views, unified patches, and three-way merges."
date: 2026-11-25
author: Recursive AI
---

# Migrate from DiffPlex to OneDiff in C#

Replace DiffPlex’s inline builder with Diff.Lines, then port the result handling, side-by-side views, unified patches, and three-way merges.

November 25, 2026 · Recursive AI

[OneDiff](https://recursiveai.org/onediff/), a C# text diff and merge library, is free and open source from Recursive AI, under [MIT or Apache-2.0](https://github.com/recursive-ai-oss/onediff-csharp/blob/6443915c4136cc8c5a49fa2543322011665f309e/README.md#license). [NuGet](https://www.nuget.org/packages/RecursiveAI.OneDiff/1.0.1) · [GitHub](https://github.com/recursive-ai-oss/onediff-csharp/tree/v1.0.1)

There’s no compatibility layer: port the code that reads each diff result.

`dotnet add package RecursiveAI.OneDiff --version 1.0.1`

OneDiff version of DiffPlex’s `InlineDiffBuilder` example (the original is below).

*Program.cs · OneDiff 1.0.1 · .NET 10*

```
using OneDiff;
 
const string before = "start\ntimeout=10\nend";
const string after = "start\ntimeout=20\nend";
var diff = Diff.Lines(before, after);
foreach (var line in diff.Lines)
{
    var prefix = line.Kind switch
    {
        EditKind.Delete => "- ", EditKind.Insert => "+ ", _ => "  "
    };
    Console.WriteLine(prefix + line.Text);
}
```

*Output*

```
  start
- timeout=10
+ timeout=20
  end
```

## Port the inline line diff

Run the examples in separate .NET 10 console projects. The original below uses [DiffPlex 1.9.0](https://www.nuget.org/packages/DiffPlex/1.9.0) and the [inline builder pattern from its README](https://github.com/mmanela/diffplex#usage). It sets `ignoreWhiteSpace: false` explicitly.

`dotnet add package DiffPlex --version 1.9.0`

*Program.cs · DiffPlex 1.9.0 · .NET 10*

```
using DiffPlex.DiffBuilder;
using DiffPlex.DiffBuilder.Model;
 
const string before = "start\ntimeout=10\nend";
const string after = "start\ntimeout=20\nend";
var diff = InlineDiffBuilder.Diff(before, after, ignoreWhiteSpace: false);
foreach (var line in diff.Lines)
{
    var prefix = line.Type switch
    {
        ChangeType.Deleted => "- ", ChangeType.Inserted => "+ ", _ => "  "
    };
    Console.WriteLine(prefix + line.Text);
}
```

*Output*

```
  start
- timeout=10
+ timeout=20
  end
```

## Map the text APIs and result types

These are replacements for the same tasks, not promises of identical token boundaries or output. The [pinned OneDiff mapping](https://github.com/recursive-ai-oss/onediff-csharp/blob/6443915c4136cc8c5a49fa2543322011665f309e/docs/migrating-from-diffplex.md) covers additional chunkers and options.

| DiffPlex 1.9.0 | OneDiff 1.0.1 |
|---|---|
| `InlineDiffBuilder.Diff` → `DiffPaneModel.Lines` | `Diff.Lines` → `TextDiff.Lines`. `DiffRun.Text` is the line text; `DiffRun.Kind` is `Equal`, `Delete`, or `Insert`. |
| `DiffPiece.Position`, `DiffPaneModel.HasDifferences` | Read `OldLine` and `NewLine` separately: both are one-based and the missing side is null. Use `!diff.Script.IsIdentical` for differences. |
| `Differ.CreateLineDiffs` with whitespace significant | `Diff.Lines`. For low-level changes use `TextDiff.Script`, whose ranges index tokens. Line tokens include the terminator, so CRLF and LF differ. |
| `Differ.CreateWordDiffs` with caller-supplied separators | `Diff.Words` uses its own token boundaries. To retain your separators, split both strings yourself and pass the chunks to `Diff.Sequences<string>`. |
| `SideBySideDiffBuilder.Diff` → two pane lists | `Diff.SideBySide` → `Rows`. Use `Left` and `Right`; missing cells are null, not `Imaginary` entries. `DiffPiece.SubPieces` maps to `SideBySideCell.Parts` for word highlights. |
| `UnidiffRenderer.GenerateUnidiff` with both ignore flags false | `Diff.Unified` takes both texts, names, and context size. It has no ignore-case or ignore-whitespace flags or overload taking a precomputed `TextDiff`. |
| `ThreeWayDiffer.CreateMerge` with line chunking and both ignore flags false | `Diff.Merge(baseText, ours: oldText, theirs: newText)` returns `TextMerge`. Read `!merge.HasConflicts` instead of `IsSuccessful`, and use `merge.Conflicts` for details rather than `ConflictBlocks`. `merge.Text` is a string, not a list of pieces, and includes markers for unresolved conflicts. |

## Compare a side-by-side row, unified patch, and merge

Each version prints the two cells on the changed row, a patch with one context line, and the number of conflicts when two edits change the same base line. The DiffPlex calls use the [unified renderer](https://github.com/mmanela/diffplex#unidiffrenderer-class) and [three-way differ](https://github.com/mmanela/diffplex#ithreewaydiffer-interface); the result members below are from the released 1.9.0 package.

*Program.cs · DiffPlex 1.9.0 · .NET 10*

```
using DiffPlex;
using DiffPlex.Chunkers;
using DiffPlex.DiffBuilder;
using DiffPlex.Renderer;
 
const string before = "start\ntimeout=10\nend\n";
const string ours = "start\ntimeout=20\nend\n";
const string theirs = "start\ntimeout=30\nend\n";
 
var view = SideBySideDiffBuilder.Diff(before, ours, false, false);
Console.WriteLine($"{view.OldText.Lines[1].Text} | {view.NewText.Lines[1].Text}");
Console.WriteLine(UnidiffRenderer.GenerateUnidiff(
    before, ours, "before.txt", "after.txt", false, false, 1).TrimEnd());
var merge = new ThreeWayDiffer().CreateMerge(
    before, ours, theirs, false, false, LineChunker.Instance);
Console.WriteLine($"Conflicts: {merge.ConflictBlocks.Count}");
```

*Program.cs · OneDiff 1.0.1 · .NET 10*

```
using OneDiff;
 
const string before = "start\ntimeout=10\nend\n";
const string ours = "start\ntimeout=20\nend\n";
const string theirs = "start\ntimeout=30\nend\n";
 
var view = Diff.SideBySide(before, ours);
Console.WriteLine($"{view.Rows[1].Left?.Text} | {view.Rows[1].Right?.Text}");
Console.WriteLine(Diff.Unified(before, ours, "before.txt", "after.txt", 1).TrimEnd());
var merge = Diff.Merge(before, ours: ours, theirs: theirs);
Console.WriteLine($"Conflicts: {merge.ConflictCount}");
```

*Output from both programs*

```
timeout=10 | timeout=20
--- before.txt
+++ after.txt
@@ -1,3 +1,3 @@
 start
-timeout=10
+timeout=20
 end
Conflicts: 1
```

## Check behavior before removing DiffPlex

- **Line endings and comparison rules:** test LF, CRLF, missing final newlines, and whitespace-only edits. For a display that ignores whitespace, start with `Diff.LinesUsing` and `TokenComparer.IgnoreWhiteSpaceChanges` or `IgnoreAllWhiteSpace` from `OneDiff.Tokenization`. Check which rule matches your input; neither is an automatic flag translation.
- **Patches:** compare the patched result with the intended new text, not just the patch’s spelling. For a normalized display rather than a patch you can apply, render a comparer-based line diff with `Diff.ToMarkdown` or `Diff.ToTerminal`.
- **Merges:** keep the base, old, and new inputs in that order. Test adjacent edits too: OneDiff treats changes on adjacent lines as a conflict. Check the conflict result before saving merged text.

See the [OneDiff getting-started guide](https://recursiveai.org/onediff/docs/getting-started/) and the [unified patch application example](https://recursiveai.org/onediff/cookbook/apply-unified-patch/) for the next steps.
