BeneficialStrategies.Iso20022.Messages.Validation
1.1.0-alpha
dotnet add package BeneficialStrategies.Iso20022.Messages.Validation --version 1.1.0-alpha
NuGet\Install-Package BeneficialStrategies.Iso20022.Messages.Validation -Version 1.1.0-alpha
<PackageReference Include="BeneficialStrategies.Iso20022.Messages.Validation" Version="1.1.0-alpha" />
<PackageVersion Include="BeneficialStrategies.Iso20022.Messages.Validation" Version="1.1.0-alpha" />
<PackageReference Include="BeneficialStrategies.Iso20022.Messages.Validation" />
paket add BeneficialStrategies.Iso20022.Messages.Validation --version 1.1.0-alpha
#r "nuget: BeneficialStrategies.Iso20022.Messages.Validation, 1.1.0-alpha"
#:package BeneficialStrategies.Iso20022.Messages.Validation@1.1.0-alpha
#addin nuget:?package=BeneficialStrategies.Iso20022.Messages.Validation&version=1.1.0-alpha&prerelease
#tool nuget:?package=BeneficialStrategies.Iso20022.Messages.Validation&version=1.1.0-alpha&prerelease

BeneficialStrategies.Iso20022.Messages.Validation
FluentValidation validators for the interfaces of the ISO 20022 messages, components and choices: the rules the type system alone cannot express, such as cross-field rules and the check of a code against a registry.
The rules the C# type system alone cannot express: cross-field rules ("a case identification may appear in at most one of three possible locations") and the check of a code against a registry. The package is in alpha: it covers a part of the model (see "What is covered" below), not all of it.
The validators are written for the interfaces of the model (IValidator<IGroupHeader131>), not for any particular class, so they validate whatever implements the interface: a class of your own, the ready-made records, or an object built at run time. The format of each member is already enforced by its type; the validators add what a type cannot say. Three examples follow, each a step further.
What is covered
- 44 message definitions in three business areas, one version of each family (chosen by the policy in
docs/Validators.md): pacs (9: customer and institution credit transfer, direct debit, return, reversal, status report and request, multilateral settlement), pain (12: customer credit transfer and direct debit initiation, status report, reversal, payment activation, and the mandate messages) and camt (23: case management and investigations, limits, reservations, standing orders, liquidity transfers, currency exchange rate and general business information). Of the 3,339 message definitions of the model, the rest have no validator yet. - 1,184 components and 62 choices, the ones those messages use, and 8 validators for code sets.
- A message without a validator is still checked for the format of each member by its type (the primitives), so a wrong IBAN, a malformed date or a text that is too long is refused when the object is made. What is missing is the cross-field rules and the registry checks of that message.
The validators of more areas (for example reda, acmt, admi, sese and semt) follow; the order depends on what people ask for, so open an issue for the message you need.
How to use
Your own class
You do not need the message records. Take an interface of the model, IDateAndPlaceOfBirth1, and implement it in a class of your own:
// A class of yours that has the shape of the ISO 20022 component
public sealed class MyBirth(string country) : IDateAndPlaceOfBirth1
{
public ISODate BirthDate => new DateOnly(1990, 1, 1);
public Max35Text? ProvinceOfBirth => null;
public Max35Text CityOfBirth => "Springfield";
public CountryCode CountryOfBirth => country; // a code: two upper-case letters, and a country that exists
}
Register the validators, say which countries are acceptable, and validate:
// The acceptable country codes are yours to say; without a list nothing is rejected on that basis.
var countries = new InMemoryExternalCodeRegistry<CountryCode>();
countries.Add("US");
var services = new ServiceCollection();
services.AddIso20022Validators();
services.AddSingleton<IExternalCodeRegistry<CountryCode>>(countries);
using var provider = services.BuildServiceProvider();
var validator = provider.GetRequiredService<IValidator<IDateAndPlaceOfBirth1>>();
foreach (var country in new[] { "US", "ZZ" })
{
var result = validator.Validate(new MyBirth(country));
Console.WriteLine($"{country}: IsValid={result.IsValid}");
foreach (var error in result.Errors)
Console.WriteLine($" {error.PropertyName}: {error.ErrorMessage}");
}
US: IsValid=True
ZZ: IsValid=False
CountryOfBirth.ExternalCodeRegistryRule: 'ZZ' is not an acceptable value for CountryCode (ExternalCodeRegistryRule).
Anything that implements the interface gets the same rules and the same messages. Try the project yourself.
With the message records
You would rather not write the classes: ISO 20022 has thousands of them. BeneficialStrategies.Iso20022.Messages.Records has every message, component and choice as a ready-made class, and they implement the interfaces, so the same validators work on them. This validates camt.056.001.10, first a well-formed request:
// A well-formed cancellation request.
var request = new FIToFIPaymentCancellationRequestV10
{
Assignment = new CaseAssignment5
{
Identification = "CASE-2026-0001",
Assigner = new Agent { FinancialInstitutionIdentification = new() { BICFI = "AAAAGB2L" } },
Assignee = new Agent { FinancialInstitutionIdentification = new() { BICFI = "BBBBUS33" } },
CreationDateTime = new DateTime(2026, 8, 17, 9, 0, 0),
},
Underlying = [new UnderlyingTransaction28 { TransactionInformation = [new PaymentTransaction137()] }],
};
Console.WriteLine($"IsValid={validator.Validate(request).IsValid}"); // IsValid=True
then the same with a case identification at the message level and at the transaction level, a rule of the specification that no C# type could express on its own:
// The same message with a case identification at the message level and at the transaction level: a rule of the specification
// (MessageOrGroupCaseRule) that no property type can enforce, since both places are optional on their own.
Case5 TheCase() => new()
{
Identification = "CASE-2026-0001",
Creator = new Agent { FinancialInstitutionIdentification = new() { BICFI = "AAAAGB2L" } },
};
var twice = request with
{
Case = TheCase(),
Underlying = [new UnderlyingTransaction28 { TransactionInformation = [new PaymentTransaction137 { Case = TheCase() }] }],
};
var result = validator.Validate(twice);
Console.WriteLine($"IsValid={result.IsValid}"); // IsValid=False
foreach (var error in result.Errors)
Console.WriteLine($" {error.PropertyName}: {error.ErrorMessage}");
IsValid=False
MessageOrGroupCaseRule: Case identification must appear in at most one location: message-level Case, Underlying.OriginalGroupInformationAndCancellation.Case, or Underlying.TransactionInformation.Case (MessageOrGroupCaseRule / MessageOrTransactionCaseRule).
Try the project yourself.
Without the classes: the Factory
The records are large, and perhaps you do not want 3,339 messages' worth of classes in your application. The Factory builds the class that implements an interface on the fly, the first time it is asked for, so you name the interface and write no implementation:
// An object for the interface, with its members set: no class to write
var birth = IsoDataFactory.Make<IDateAndPlaceOfBirth1>(b => b
.Set(x => x.BirthDate).To(new DateOnly(1990, 1, 1))
.Set(x => x.CityOfBirth).To("Springfield")
.Set(x => x.CountryOfBirth).To("ZZ"));
var result = validator.Validate(birth);
Console.WriteLine($"IsValid={result.IsValid}"); // IsValid=False
foreach (var error in result.Errors)
Console.WriteLine($" {error.PropertyName}: {error.ErrorMessage}");
The Factory also reads XML into the interfaces, so a document can be validated with no records at all: see BeneficialStrategies.Iso20022.Validation.Xml. Try the project yourself.
More
- Documentation, release notes and issues: https://github.com/Beneficial-Strategies/iso-20022-messages-validation
- License: MIT. Status: alpha.
Registering the validators
AddIso20022Validators() registers all of them with a standard IServiceCollection; narrower overloads register one business area, the exact closure one message needs, or whatever a predicate selects. See docs/RegisteringValidators.md.
Code sets that live outside the library
Country codes, currency codes and ISO's own externally maintained code lists are checked for format by their type; which values are acceptable lives in a registry you can populate or replace. See docs/ExternalCodeSets.md.
Raw XML or JSON off a queue
BeneficialStrategies.Iso20022.Validation.Xml reads XML into an object and validates it in one call, and a payload package validates raw XML or JSON text as it arrives. They work with these validators because both use IValidator<T>; none of them depends on the others.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- BeneficialStrategies.Iso20022.Messages (>= 1.0.1 && < 1.1.0)
- BeneficialStrategies.Iso20022.Primitives (>= 1.1.1 && < 1.2.0)
- FluentValidation (>= 11.12.0)
- FluentValidation.DependencyInjectionExtensions (>= 11.12.0)
-
net10.0
- BeneficialStrategies.Iso20022.Messages (>= 1.0.1 && < 1.1.0)
- BeneficialStrategies.Iso20022.Primitives (>= 1.1.1 && < 1.2.0)
- FluentValidation (>= 11.12.0)
- FluentValidation.DependencyInjectionExtensions (>= 11.12.0)
-
net8.0
- BeneficialStrategies.Iso20022.Messages (>= 1.0.1 && < 1.1.0)
- BeneficialStrategies.Iso20022.Primitives (>= 1.1.1 && < 1.2.0)
- FluentValidation (>= 11.12.0)
- FluentValidation.DependencyInjectionExtensions (>= 11.12.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.0-alpha | 62 | 10/26/2026 |
| 1.0.0-alpha | 60 | 10/23/2026 |
Breaking change: The package needs Primitives 1.1.0-alpha or later, whose types check what their standards say; its dependency ranges end before the first pre-release of the next second part (#10).
Fixed: Four tests use a UTI that does not start with a valid LEI (#3).