Summary
Enable CA1062 ("Validate arguments of externally visible methods") as a build-enforced analyzer rule so missing null-argument guards on public/protected APIs are caught deterministically at build time instead of ad hoc during code review.
Motivation
Missing ArgumentNullException guards on public entry points are a recurring manual review nit (including from the Copilot PR reviewer). Each occurrence currently costs a review round-trip: reviewer spots it, author adds ArgumentNullException.ThrowIfNull(...), re-review. CA1062 catches the entire class at compile time, consistently, before a PR is ever opened.
This rule is disabled by default in the SDK's current analysis mode (AnalysisMode=Default), so it never fires today even though EnableNETAnalyzers=true and TreatWarningsAsErrors=true are set in eng/build/Engineering.props.
Evidence (from a local AnalysisMode=All build)
CA1062 fires on hand-written production code that skips argument validation, e.g. in ConnectorClientBase:
CallConnectorAsync<TResponse>(HttpMethod method, ...) — method not validated before use.
CallConnectorAsync(HttpMethod method, ...) (no-body overload) — same.
New code such as ConnectorTriggerPayload already validates via ArgumentNullException.ThrowIfNull, so it is clean — which shows the rule aligns with the direction the codebase is already moving.
Scope / considerations
- Generated code is in scope. The generated clients are produced by our own CodefulSdkGenerator (BPM repo) and are a core part of the value proposition; they must not ship missing guards. Enabling CA1062 will surface any generated entry points lacking validation — if it flags generated code, the fix belongs in the generator's emit templates, not a per-file suppression.
- Severity: start as
warning (which TreatWarningsAsErrors escalates to an error) or suggestion for a soft rollout, then promote.
- Rollout: enable via
.editorconfig (dotnet_diagnostic.CA1062.severity = warning) rather than raising the whole AnalysisMode, to keep the change targeted and avoid the ~17k unrelated diagnostics that AnalysisMode=All produces.
- Note: CA1062 has known limitations (it may not track validation performed in a called helper), so expect a few false positives to suppress with justification.
Acceptance criteria
Filed from analysis on PR #196; not part of that PR's scope.
Summary
Enable CA1062 ("Validate arguments of externally visible methods") as a build-enforced analyzer rule so missing null-argument guards on public/protected APIs are caught deterministically at build time instead of ad hoc during code review.
Motivation
Missing
ArgumentNullExceptionguards on public entry points are a recurring manual review nit (including from the Copilot PR reviewer). Each occurrence currently costs a review round-trip: reviewer spots it, author addsArgumentNullException.ThrowIfNull(...), re-review. CA1062 catches the entire class at compile time, consistently, before a PR is ever opened.This rule is disabled by default in the SDK's current analysis mode (
AnalysisMode=Default), so it never fires today even thoughEnableNETAnalyzers=trueandTreatWarningsAsErrors=trueare set ineng/build/Engineering.props.Evidence (from a local
AnalysisMode=Allbuild)CA1062 fires on hand-written production code that skips argument validation, e.g. in
ConnectorClientBase:CallConnectorAsync<TResponse>(HttpMethod method, ...)—methodnot validated before use.CallConnectorAsync(HttpMethod method, ...)(no-body overload) — same.New code such as
ConnectorTriggerPayloadalready validates viaArgumentNullException.ThrowIfNull, so it is clean — which shows the rule aligns with the direction the codebase is already moving.Scope / considerations
warning(whichTreatWarningsAsErrorsescalates to an error) orsuggestionfor a soft rollout, then promote..editorconfig(dotnet_diagnostic.CA1062.severity = warning) rather than raising the wholeAnalysisMode, to keep the change targeted and avoid the ~17k unrelated diagnostics thatAnalysisMode=Allproduces.Acceptance criteria
dotnet_diagnostic.CA1062.severityset in.editorconfig.ArgumentNullException.ThrowIfNull).Filed from analysis on PR #196; not part of that PR's scope.