Template validation rejects CallShared/CallScript with a parameters object (blocks deploy) #150
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Template validation (the pre-deploy gate) rejects every
Scripts.CallShared("name", new { ... })call that passes arguments, so a template that calls a shared script with parameters cannot be deployed.CallScriptuses the same check and is affected the same way.Cause
SemanticValidator.ExtractCallsOfType(src/ZB.MOM.WW.ScadaBridge.TemplateEngine/Validation/SemanticValidator.cs) treats each comma-separated argument after the script name as one positional argument.ValidateCallParameters(line ~361, called at lines 104 and 134) then requires that count to equal the number of declaredParameterDefinitions.The runtime has no positional form.
ScriptCallHelper.CallShared(string scriptName, object? parameters = null, CancellationToken ct = default)andScriptRuntimeContext.CallScript(string scriptName, object? parameters = null)take ONE parameters object, whichScriptArgs.Normalizeturns into a name→value dictionary. A correct call always counts as 1 argument:calls 'X' with 1 arguments but N are expected... with 1 arguments but 0 are expectedIt passes only when exactly one parameter is declared, and then the positional type check compares the whole object expression against that one declared type.
Repro (DEV vd03, 2026-11-28)
SendNotificationExample(id 3) declaresNotificationList,Subject,Body.NotifyExample(id 49), Call scriptSendTestNotification:await Scripts.CallShared("SendNotificationExample", new { NotificationList = ..., Subject = ..., Body = ... })template validate --id 49→isValid:false, category 7 (ParameterMismatch):calls 'SendNotificationExample' with 1 arguments but 3 are expected.... with 1 arguments but 0 are expected.The same code runs correctly in Test Run and on the site once deployed.
Workaround in use
Put the script name in a variable (
var name = "SendNotificationExample"; Scripts.CallShared(name, new { ... })).ExtractStringArgumentonly recognises a string literal, so the call is no longer validated at all. That is howNotifyExamplewas deployed on vd03.Fix direction
new { A = ..., B = ... }), validate by name: required declared parameters must be present, unknown names flagged (or warned), and types checked per member where they can be inferred.SemanticValidatorTestsfor CallShared and CallScript with an anonymous object, a dictionary variable, and no arguments. Today no test calls either one with arguments.Fixed in
607ffc2e(main). CallShared/CallScript calls are now parsed with Roslyn and the single parameters object is validated by name: an anonymous object must supply every required declared parameter (error otherwise), undeclared names are warnings, literal member types are checked; any other expression (variable, dictionary, method call, null) is not checked; no parameters argument is an error only when required parameters are declared. The literal-name formScripts.CallShared("SendNotificationExample", new { ... })now passes validation, so the variable-name workaround is no longer needed once this build is deployed.