Validation messages that resolve to a resource string are currently dropped with SP0016, and cannot be recovered by reading a constant.
Why the constant route does not work
A localized application writes its messages as:
RuleFor(_ => _.Title).NotEmpty().WithMessage(_ => RequestMessages.TitleRequired);
where RequestMessages.TitleRequired is generated from a .resx by the MSBuild:Compile generator:
internal static string TitleRequired {
get { return ResourceManager.GetString("TitleRequired", resourceCulture); }
}
That is a runtime, culture-dependent lookup. It has no constant value, so HasConstantValue / GetConstantValue return nothing and the message is correctly reported as computed. #2397 recovers the lambda-returning-a-literal and lambda-returning-a-const shapes, but those do not occur in a localized application.
Measured on a real production application: 510 WithMessage calls, all of this shape, accounting for 247 of its SP0016 diagnostics.
Suggested direction
The Screenplay language has a $strings. form for exactly this. Rather than resolving the message to text at generation time — which would bake one culture into a document meant to describe the application — emit the key:
message $strings.TitleRequired
The key is statically available: it is the GetString argument in the generated designer property, and equivalently the property name. Recovering it means recognizing that a symbol is a resx designer property and taking its name, rather than trying to evaluate it.
Points worth deciding:
- Whether to qualify the key with the resource class (
$strings.RequestMessages.TitleRequired) or emit it bare, and what the language's $strings. form actually accepts.
- Whether to verify the key exists in the
.resx at generation time, or trust the symbol.
- What to do when a message is composed rather than referenced directly (
string.Format(...), interpolation) — those should stay SP0016.
Acceptance
A validation rule whose message references a resource designer property emits a $strings. message rather than being dropped; SP0016 on the reference application falls by roughly 247; the document still compiles under the Screenplay compiler; generation stays deterministic. Messages that are genuinely computed continue to be reported.
Related: #2397 (where this was discovered and why the constant route was insufficient).
Validation messages that resolve to a resource string are currently dropped with
SP0016, and cannot be recovered by reading a constant.Why the constant route does not work
A localized application writes its messages as:
where
RequestMessages.TitleRequiredis generated from a.resxby theMSBuild:Compilegenerator:That is a runtime, culture-dependent lookup. It has no constant value, so
HasConstantValue/GetConstantValuereturn nothing and the message is correctly reported as computed. #2397 recovers the lambda-returning-a-literal and lambda-returning-a-constshapes, but those do not occur in a localized application.Measured on a real production application: 510
WithMessagecalls, all of this shape, accounting for 247 of itsSP0016diagnostics.Suggested direction
The Screenplay language has a
$strings.form for exactly this. Rather than resolving the message to text at generation time — which would bake one culture into a document meant to describe the application — emit the key:The key is statically available: it is the
GetStringargument in the generated designer property, and equivalently the property name. Recovering it means recognizing that a symbol is a resx designer property and taking its name, rather than trying to evaluate it.Points worth deciding:
$strings.RequestMessages.TitleRequired) or emit it bare, and what the language's$strings.form actually accepts..resxat generation time, or trust the symbol.string.Format(...), interpolation) — those should staySP0016.Acceptance
A validation rule whose message references a resource designer property emits a
$strings.message rather than being dropped;SP0016on the reference application falls by roughly 247; the document still compiles under the Screenplay compiler; generation stays deterministic. Messages that are genuinely computed continue to be reported.Related: #2397 (where this was discovered and why the constant route was insufficient).