---
title: "Get structured merge conflicts in C#"
url: https://recursiveai.org/onediff/cookbook/merge-text-without-conflict-markers/
description: "Read three-way merge conflicts as C# objects with original and edited text plus line numbers, without parsing conflict markers."
version: "1.0.1"
---

# Get structured merge conflicts in C#

**OneDiff** is a free, open-source diff library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneDiff) · [GitHub](https://github.com/recursive-ai-oss/onediff-csharp) · [Docs](https://recursiveai.org/onediff/docs/) · [Download example (.zip)](https://recursiveai.org/onediff/cookbook/merge-text-without-conflict-markers/merge-text-without-conflict-markers.zip)

In a three-way merge, read each conflict directly instead of parsing markers.

```shell
dotnet add package RecursiveAI.OneDiff
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneDiff;
// Arguments: base, ours, theirs.
var merge = Diff.Merge("on\n","off\n","auto\n");
foreach (var c in merge.Conflicts)
    Console.Write($"Line {c.BaseLine}\n"
        + $"Base: {c.BaseText}"
        + $"Ours: {c.OursText}"
        + $"Theirs: {c.TheirsText}");
```

Unzip [the example](https://recursiveai.org/onediff/cookbook/merge-text-without-conflict-markers/merge-text-without-conflict-markers.zip), then `dotnet run`.

Prints:

```text
Line 1
Base: on
Ours: off
Theirs: auto
```

`merge.Conflicts` is empty when the two edits merge without a disagreement. The program reads the conflicts without parsing `merge.Text`, which still contains markers by default when there is an unresolved conflict.

## Variations

**Use the edited versions’ line numbers.** Add braces around the loop body and insert this line inside it to get the starting lines for a side-by-side view. All three line numbers are one-based.

```csharp
Console.WriteLine($"Ours: {c.OursLine}, theirs: {c.TheirsLine}");
```

**Produce marker-free text by explicitly taking ours.** Replace the merge call with this version. `merge.Text` is now `off\n`, but `merge.Conflicts` still contains the disagreement for review.

```csharp
var merge = Diff.Merge("on\n", "off\n", "auto\n",
    new OneDiff.Merge.MergeSettings
    {
        Resolution = OneDiff.Merge.ConflictResolution.Ours
    });
```

## Related recipes

- [Show the original lines in merge conflict markers](https://recursiveai.org/onediff/cookbook/include-base-text-in-merge-conflicts/)
- [Merge independent text edits](https://recursiveai.org/onediff/cookbook/three-way-text-merge/)

## The short answer

Iterate `Diff.Merge(baseText, ours, theirs).Conflicts` to get `MergeConflict` objects. Each gives you the three pieces of text with their line endings, a starting line for each version, and a `Region` with the underlying ranges. You can use these fields in a review tool even when you never display the merged text with markers.

## How do you build a three-way merge view without parsing markers?

For a list of conflicts, loop over `Conflicts` in the order returned and show the base, ours, and theirs as separate fields. Use the corresponding line number for each field rather than using `BaseLine` to locate all three. Insertions or deletions earlier in an edited file can shift its later lines relative to the base. Keep the original line endings if you will use a selection to reconstruct text; trim them only for a display label.

Use `Regions` instead if the view also needs the ranges between conflicts, including the parts the library could merge without review. The [structured result](https://recursiveai.org/onediff/docs/merge/#structured-result) describes how the regions cover all three inputs. In a conflict split into several pieces, the first conflicting piece carries the base range, so don’t assume that each displayed piece has a separate span of original text.

## When do three-way merge conflicts occur?

The merge compares each edit against the same base, so a change on just one side does not ordinarily need a decision. Identical changes to the same range are taken once. In the example, both sides replace the same value in different ways, so the result has one conflict. Even edits whose ranges only touch can conflict in this merge. Check the result rather than guessing from the sets of changed line numbers.

`ConflictCount` counts unresolved conflicts. If your application supplies a resolution policy, it can drop to zero even when the `Conflicts` list is nonempty. Use the count to decide whether output is still marked for review, and use the list if you need to report what was disputed even after automatic resolution.
