---
title: "Polly: fault injection without a crash in C# | VulCode"
description: "In Polly, the .NET resilience library, FaultGenerator in C# returns null instead of throwing InvalidOperationException when there is no fault to inject."
url: "https://vulcode.com/en/opensource/contributions/polly"
lang: "en"
---

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

App-vNext/Polly

# Polly

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.

[See the repository](https://github.com/App-vNext/Polly) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: C#
- **GitHub stars**: 14,255
- **Merged changes**: 1
- **Project site**: [thepollyproject.org](https://www.thepollyproject.org)

## What we changed

FaultGenerator returns null when there is no fault to inject, instead of throwing InvalidOperationException and failing a call the strategy was meant to leave alone. The fix shipped in version 8.8.0.

### What this work shows

- Nullable value types and structs in C#

- Chaos testing with Simmy

- xUnit unit tests

What was broken

### An empty fault generator failed the call

A FaultGenerator with no exceptions registered, or with all weights at zero, threw InvalidOperationException ("Nullable object must have a value"). The null-forgiving operator (!) does nothing at runtime, so .Value on an empty Nullable failed a call that ChaosFaultStrategy was meant to leave alone.

How we fixed it

### No fault means null

The delegate now passes the result through ?.Exception, as the sibling OutcomeGenerator does. When there is no fault it returns null and the strategy lets the call through untouched, which two new tests check.

[#3220](https://github.com/App-vNext/Polly/pull/3220)

## Merged change

1 6 September 2026

- [01 #3220Merged 6 September 2026 Return null from FaultGenerator when no fault is generated](https://github.com/App-vNext/Polly/pull/3220)

## What it taught us

We catch bugs the compiler lets through: the null-forgiving operator (!) in C# does not guard against an empty Nullable at runtime. We back such a fix with tests that fail on the old code and pass on the new one.

[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)

- [**FluentValidation** C# · 9,780 stars A popular .NET library for writing strongly typed validation rules in a fluent style, such as RuleFor(...).InclusiveBetween(...).](https://vulcode.com/en/opensource/contributions/fluentvalidation)

- [**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)
