/orleans:orleans-result-patternfrom orleans
Provides a version-tolerant result pattern for Microsoft Orleans 8+ grain calls, returning success/error without exceptions. Includes implicit conversions and pattern-matching consumption.
Ships in orleans. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Use when designing Microsoft Orleans 8+ grain contracts that need to signal failure without throwing exceptions, in a form that (a) serializes cleanly under Orleans' version-tolerant serializer, (b) integrates with ASP.NET Core minimal APIs + MVC, and (c) supports RFC7807 ValidationProblemDetails responses.
Apply when any of these is true:
UserNotFoundException etc.) to return results insteadOk / NotFound / ValidationProblemFluentResults and finding it doesn't play well with Orleans serialization (requires manual annotation of every type involved)T, ErrorNr, (ErrorNr, message), Error, and Collection<Error> to keep return statements short[Flags]-enum-based tagging of validation errors so TryAsValidationErrors can produce RFC7807 outputAvoid for genuinely exceptional conditions (out-of-memory, serialization bugs, contract violations) — exceptions still belong there.
Using exceptions for flow control is an antipattern:
_ = to express intentional discard.Orleans 8+ requires that every type crossing a grain boundary be annotated ([GenerateSerializer] + [Id]) or serializable through another mechanism. Result implementations that allow arbitrary objects inside errors (e.g. exceptions) require open-ended work to serialize. Orleans.Results avoids this by defining an error as enum + string message only, which serializes trivially and is fully version-tolerant under Orleans 8+ guidelines.
Result, Result<T>, and Error are marked with Orleans' [Immutable] attribute, letting the silo pass references instead of deep-copying on within-silo grain calls.
Modern.CSharp.Templates installed:dotnet new install Modern.CSharp.Templates
Run inside the project that contains grain interfaces — or inside a project that is referenced by projects containing grain interfaces. The generated Result<T> types need to be visible to both grain contracts and their callers:
dotnet new mcs-orleans-results
The template takes no parameters and drops two files into the current folder:
| File | Purpose |
|---|---|
ErrorNr.cs | enum ErrorNr — domain error codes; edit freely |
Result.cs | Result : ResultBase<ErrorNr> + Result<T> : ResultBase<ErrorNr, T> + Error record — wrap the library base types to avoid repeating <ErrorNr> on every method signature |
Example namespace in both files with your project namespace.ErrorNr enum.TryAsValidationErrors for RFC7807 responses, make ErrorNr a [Flags] enum with a ValidationError marker — see section 7.public enum ErrorNr
{
UserNotFound = 1
}
Factory helpers keep call sites terse:
static class Errors
{
public static Result.Error UserNotFound(int id) =>
new(ErrorNr.UserNotFound, $"User {id} not found");
}
interface ITenant : IGrainWithStringKey
{
Task<Result<string>> GetUser(int id);
}
class Tenant : Grain, ITenant
{
public Task<Result<string>> GetUser(int id) => Task.FromResult<Result<string>>(
id >= 0 && id < S.Users.Count
? S.Users[id] // implicit T → Result<T>
: Errors.UserNotFound(id) // implicit Error → Result<T>
);
}
app.MapGet("minimalapis/users/{id}", async (IClusterClient client, int id)
=> await client.GetGrain<ITenant>("A").GetUser(id) switch
{
{ IsSuccess: true } r => Results.Ok(r.Value),
{ ErrorNr: ErrorNr.UserNotFound } r => Results.NotFound(r.ErrorsText),
{ } r => throw r.UnhandledErrorException()
}
);
[HttpGet("mvc/users/{id}")]
public async Task<ActionResult<string>> GetUser(int id)
=> await client.GetGrain<ITenant>("A").GetUser(id) switch
{
{ IsSuccess: true } r => Ok(r.Value),
{ ErrorNr: ErrorNr.UserNotFound } r => NotFound(r.ErrorsText),
{ } r => throw r.UnhandledErrorException()
};
{ IsSuccess: true } r => ... — matches the success case; r.Value is the T{ ErrorNr: ErrorNr.X } r => ... — matches a specific error code; r.ErrorsText is the joined message string{ } r => throw r.UnhandledErrorException() — catch-all for unexpected error codes; throws a descriptive exception so API middleware can map it to 500Each endpoint should enumerate only the error codes it specifically handles; everything else goes to the final throw.
For RFC7807 ValidationProblemDetails responses, make ErrorNr a [Flags] enum with a ValidationError marker bit:
[Flags]
public enum ErrorNr
{
NoUsersAtAddress = 1,
ValidationError = 1024,
InvalidZipCode = 1 | ValidationError,
InvalidHouseNr = 2 | ValidationError,
}
Implement a grain that validates before acting:
public async Task<Result<string>> GetUsersAtAddress(string zip, string nr)
{
Collection<Result.Error> errors = new();
// Validation phase — don't do the work if any validation fails.
if (!ZipRegex().IsMatch(zip)) errors.Add(Errors.InvalidZipCode(zip));
if (!HouseNrRegex().IsMatch(nr)) errors.Add(Errors.InvalidHouseNr(nr));
if (errors.Any()) return errors;
// Work phase — may still return non-validation errors.
string users = "";
// ... do the work
if (users == "") errors.Add(Errors.NoUsersAtAddress($"{zip} {nr}"));
return errors.Any() ? errors : users;
}
Consume with TryAsValidationErrors:
Minimal API:
return result.TryAsValidationErrors(ErrorNr.ValidationError, out var validationErrors)
? Results.ValidationProblem(validationErrors)
: result switch
{
{ IsSuccess: true } r => Results.Ok(r.Value),
{ ErrorNr: ErrorNr.NoUsersAtAddress } r => Results.NotFound(r.ErrorsText),
{ } r => throw r.UnhandledErrorException()
};
MVC:
return result.TryAsValidationErrors(ErrorNr.ValidationError, out var validationErrors)
? ValidationProblem(new ValidationProblemDetails(validationErrors))
: result switch
{
{ IsSuccess: true } r => Ok(r.Value),
{ ErrorNr: ErrorNr.NoUsersAtAddress } r => NotFound(r.ErrorsText),
{ } r => throw r.UnhandledErrorException()
};
TryAsValidationErrors returns true only when the result is failed and every error in it carries the ValidationError flag. A mix of validation and non-validation errors falls through to the general switch.
async Task<Result<string>> GetString(int i) => i switch
{
0 => "Success!", // T
1 => ErrorNr.NotFound, // ErrorNr
2 => (ErrorNr.NotFound, "Not found"), // (ErrorNr, string)
3 => new Error(ErrorNr.NotFound, "Not found"), // Error
4 => new Collection<Error>(/*...*/) // Collection<Error>
};
For multiple errors sourced from an IEnumerable<Error> other than Collection<Error>, use the public constructor:
async Task<Result<string>> GetString()
{
IEnumerable<Error> errors = new HashSet<Error>();
// ... add errors
if (errors.Any()) return new(errors);
return "Success!";
}
Result, Result<T>, and Error are marked [Immutable] — Orleans skips deep-copying them on within-silo grain calls.T [Immutable] where correct.ErrorNr.cs and Result.cs live in the grain-interfaces project (or a shared project referenced by it).Example.[Flags] applied iff you use TryAsValidationErrors.switch-expression shape from section 6; the final catch-all throws r.UnhandledErrorException().What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
orleans, result-pattern, grain-contracts, error-handling, serialization
Other plugins' skills for the same job
npx claudepluginhub vincenth-net/dotnet-agentic-engineering --plugin orleans3 skills in this plugin
/orleans-multiservice-patternModular-monolith pattern for Microsoft Orleans 10 — host multiple **logical services** inside one physical silo/microservice, with project/namespace/dependency rules that let any logical service later be extracted to its own physical microservice with minimal changes. Use when starting a new Orleans 10 backend for a single team, when deferring real microservices until genuinely needed (MonolithFirst), when organizing a codebase to follow Conway's Law, or when you want painless future migration from in-silo grain calls to generated OpenAPI HTTP clients. Scaffolds `Apis.<S>Api`, `Contracts.<S>Contract`, and `<S>Service` projects with strict dependency directions (Apis→Contracts, Apis→Service, Service→Contracts), plus a silo host. Generated by the `mcs-orleans-multiservice` template; add more logical services via `AddLogicalService.ps1 <name>` or `--Multiservice .`./orleans-multitenantMultitenancy for Microsoft Orleans 10 with the Orleans.Multitenant NuGet package — per-tenant grain storage and tenant separation of grain calls and streams. Use when an Orleans app needs multitenancy, tenant isolation or per-tenant storage (e.g. multi-tenant SaaS), even if the package is not referenced yet; this skill adds it. Also use in a repo that references Orleans.Multitenant when getting grains or streams, configuring storage or streams, subscribing to streams, or upgrading from 4.x.