fix(application): typed Result<T>.Failure on validation failures (POM-482)#102
Merged
Merged
Conversation
…s (POM-482)
The previous reflection lookup `typeof(Result<>).MakeGenericType(t).GetMethod("Failure", new[] { typeof(Error) })`
returned `null` because the static `Failure<T>(Error)` factory lives on the
non-generic `Result` base class. `GetMethod` on a closed generic does not
surface inherited statics without `BindingFlags.FlattenHierarchy`, so the
behavior was returning `null` cast to `Result<T>` for the failure path —
silently corrupting the CQRS pipeline for any handler whose response is
`Result<TValue>`.
Resolve the static method through the non-generic `Result` type and close
it over the response's inner type via `MakeGenericMethod`. The existing
short-circuit test is upgraded from accepting the buggy `null` to asserting
`IsFailure == true` with the proper `Validation.Failed` error code/type.
All 225 unit tests in `Compendium.Application.Tests` pass.
This was referenced May 18, 2026
Merged
Open
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes POM-482 —
ValidationBehaviorwas returningnull(cast toTResponse) for theResult<T>failure path, silently corrupting the CQRS pipeline for any handler whose response isResult<TValue>.Root cause
src/Application/Compendium.Application/CQRS/Behaviors/ValidationBehavior.cs:40-44did :```csharp
var failureMethod = typeof(Result<>).MakeGenericType(resultType)
.GetMethod(nameof(Result.Failure), new[] { typeof(Error) });
var result = failureMethod?.Invoke(null, new object[] { error }); // ← null in production
return (TResponse)result!;
```
`Failure(Error)` is a static on the non-generic `Result` base class (
src/Core/Compendium.Core/Results/Result.cs:88). `GetMethod` on the closed generic `Result` does not surface inherited statics without `BindingFlags.FlattenHierarchy`, so the lookup returned `null` and the null-conditional invocation silently produced `null`.Fix
Resolve the static through the non-generic `Result` type and close it over the response's inner type via `MakeGenericMethod` :
```csharp
var failureMethod = typeof(Result)
.GetMethods(BindingFlags.Public | BindingFlags.Static)
.Single(m => m.Name == nameof(Result.Failure)
&& m.IsGenericMethodDefinition
&& m.GetParameters().Length == 1
&& m.GetParameters()[0].ParameterType == typeof(Error))
.MakeGenericMethod(resultType);
```
Test
The existing `HandleAsync_WhenInvalidAndResponseIsGenericResult_ShortCircuitsBeforeNext` was renamed to `_ReturnsFailureAndShortCircuits` and now asserts :
The previous version accepted the buggy `null` with a comment — that comment is now removed.
Verification
Release impact
After merge, target framework v1.0.1 → republishes `Compendium.Application`.
Test plan