Reliability and Error Handling (.NET)
Server-side .NET apps can fail when fetching, verifying, or loading cached feature definitions (network blips, JWKS rotation, storage round-trips). The SDK keeps evaluation predictable while making those failures visible.
Shared behavior
OnErrorreports fetch, cache, storage, signature, and JWKS failures.- After a successful load, refresh failures keep in-memory last-known-good flags.
- Signed snapshots store the exact server
defsJSON (SignedDefsJson) so cold start verification does not re-serialize models (which caused falseInvalid signatureerrors). Evaluation always uses that verified JSON. - If a typed
Featurescopy is also present and does not match the verifiedSignedDefsJson(feature keys, filters/parameters, secured flag, requirement type, metrics), the snapshot is refused (possible storage tampering) and reported viaOnError. - Legacy snapshots without
SignedDefsJsonare refused whenUseSignedDefinitionsis enabled. Clear persisted snapshots and refresh to upgrade them (typedFeaturesalone are not trusted). - WebSocket
signing-key-updatedclears the JWKS cache/snapshot, then refreshes definitions (clear completes before refresh). - Definitions revision is taken from typed
ETag, rawETag, orX-Definitions-Revision. Revision is for conditional HTTP caching — it is not part of the cryptographic signature. - Definitions and JWKS HTTP error status messages do not include remote
response bodies at Information/Error level. Enable
Debuglogging forToggly.FeatureManagementto inspect response bodies when troubleshooting.
OnError
services.Configure<TogglySettings>(options =>
{
options.AppKey = Configuration["Toggly:AppKey"];
options.Environment = Configuration["Toggly:Environment"];
options.UseSignedDefinitions = true;
options.OnError = (message, exception) =>
{
// Report to App Insights / Sentry / your logger
logger.LogWarning(exception, "Toggly: {Message}", message);
};
});
The last error is also available via IFeatureProviderDebug.GetDebugInfo()
(the concrete TogglyFeatureProvider is registered as that interface).
Clearing snapshots
Use clear APIs when recovering from a corrupt cache, after key rotation issues, or in tests:
// Clears persisted feature + JWKS snapshots (does not wipe in-memory defs)
var provider = app.Services.GetRequiredService<TogglyFeatureProvider>();
await provider.ClearPersistedSnapshotsAsync();
// Or call the snapshot provider directly
var snapshots = app.Services.GetRequiredService<IFeatureSnapshotProvider>();
await snapshots.ClearSnapshotAsync();
await snapshots.ClearJwkSnapshotAsync();
After clearing, the next refresh rebuilds the snapshot from the definitions API. In-memory definitions stay until that refresh succeeds.