---
title: "FluentValidation: range validation fix in C# | VulCode"
description: "A fix to FluentValidation in C#: InclusiveBetween and ExclusiveBetween now reject an inverted range when the comparer returns a negative other than -1."
url: "https://vulcode.com/en/opensource/contributions/fluentvalidation"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

FluentValidation/FluentValidation

# FluentValidation

A popular .NET library for writing strongly typed validation rules in a fluent style, such as RuleFor(...).InclusiveBetween(...).

[See the repository](https://github.com/FluentValidation/FluentValidation) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: C#
- **GitHub stars**: 9,780
- **Merged changes**: 1
- **Project site**: [fluentvalidation.net](https://fluentvalidation.net)

## What we changed

InclusiveBetween and ExclusiveBetween reject an inverted range even when the comparer returns any negative number, not only -1, for example for char bounds.

### What this work shows

- The IComparer<T> contract in .NET

- Constructor argument validation

- Unit tests in xUnit

What was broken

### An inverted range was accepted silently

The RangeValidator constructor rejected a range from larger to smaller only when the comparison returned exactly -1. char.CompareTo returns the difference, so InclusiveBetween('c', 'a') was accepted and produced a rule that can never pass.

How we fixed it

### Checking the sign instead of -1

The check now tests whether the result is below zero, as the IComparer<T> contract says. We added char bound tests for InclusiveBetween and ExclusiveBetween that failed before the change.

[#2370](https://github.com/FluentValidation/FluentValidation/pull/2370)

## Merged change 1

- [#2370 fix: reject an inverted range when the comparer returns a negative other than -1 Merged 9 September 2026](https://github.com/FluentValidation/FluentValidation/pull/2370)

## What it taught us

The .NET comparison contract only promises the sign of the result. Code that checks for exactly -1 works until the first comparer that returns -2, and we can find such spots and cover them with a test.

[More about this technology: C# and .NET](https://vulcode.com/en/technologies/csharp-and-dotnet)

## Other projects we write code for

- [**ILSpy** C# · 27,138 stars An open source .NET decompiler that turns compiled assemblies back into readable C# code. It is used to inspect libraries whose source code is not at hand.](https://vulcode.com/en/opensource/contributions/ilspy)

- [**OpenRA** C# · 17,827 stars An open source real-time strategy engine for classic Westwood games such as Command & Conquer: Red Alert, written in C# with SDL and OpenGL.](https://vulcode.com/en/opensource/contributions/openra)

- [**Polly** C# · 14,255 stars A .NET library for handling transient faults: retries, circuit breakers, timeouts and fallback. Its Simmy module injects faults on purpose to test how an application copes with them.](https://vulcode.com/en/opensource/contributions/polly)

- [**Serilog** C# · 8,064 stars A structured logging library for .NET. It records events from message templates, with named properties rather than plain text.](https://vulcode.com/en/opensource/contributions/serilog)

- [**NLog** C# · 6,547 stars A flexible structured logging library for many .NET platforms, configured through layouts, filters and targets.](https://vulcode.com/en/opensource/contributions/nlog)

- [**Markdig** C# · 5,359 stars A fast CommonMark-compliant Markdown processor for .NET, with extensions such as tables, definition lists and automatic heading identifiers.](https://vulcode.com/en/opensource/contributions/markdig)

## Describe your project.

A free quote comes back within an hour during working hours.

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
