Skip to content

Diagnostics Reference — Analyzer Rules (GRxxx)

Granit.Analyzers ships Roslyn analyzers that enforce framework conventions at build time. When a build log shows a GRxxx warning or error, this page is the index. Rules marked Error fail the build.

The analyzers load automatically with the Granit.Analyzers package; Granit.Analyzers.CodeFixes adds the associated IDE code fixes.

IDSeverityRule
GRAPI001WarningAvoid the Results static class — use TypedResults
GRAPI002WarningAvoid TypedResults.BadRequest with a body — use TypedResults.Problem for RFC 7807 responses
GRAPI003ErrorMinimal API endpoint handler has an interface-typed parameter without an explicit binding attribute — add [FromServices] (or [FromQuery], [FromBody], …)
IDSeverityRule
GRSEC001WarningAvoid direct DateTime/DateTimeOffset clock access — inject IClock
GRSEC002WarningAvoid Guid.NewGuid() — use IGuidGenerator (sequential GUIDs)
GRSEC003ErrorPotential hardcoded secret detected
GRSEC004WarningAvoid direct IResponseCookies access — use IGranitCookieManager
GRSEC005WarningPrivacyExportContext subject must equal the caller
GRSEC010ErrorPII-indicative name used as a metric tag key
GRSEC011ErrorPII-indicative placeholder in a LoggerMessage template
IDSeverityRule
GRMOD001ErrorCross-module reference to an internal type — reference the module’s Contracts package instead (module system)

Zero-downtime migration safety — see Migrations.

IDSeverityRule
GRMIGA001ErrorDropColumn requires a Contract-phase annotation
GRMIGA002ErrorRenameColumn is not zero-downtime safe
GRMIGA003WarningAddColumn NOT NULL without a default value risks a table lock
GRMIGA004WarningAlterColumn with a type change requires a Contract-phase annotation
IDSeverityRule
GRBROWSING001WarningJS expression argument mixes user-controllable data (browsing security)
GREF001WarningUse SaveChangesAsync() instead of SaveChanges()
GRENUM001WarningRedundant explicit enum value

Prefer fixing the reported code. When a suppression is genuinely justified, scope it as narrowly as possible and document why:

#pragma warning disable GRSEC001 // Wall-clock comparison against an external timestamp
var skew = DateTimeOffset.UtcNow - externalTimestamp;
#pragma warning restore GRSEC001