I am trying to use #Script to validate a create request
[ValidateRequest(
Condition = "(it.CompanyId.HasValue && it.CompanyId != Guid.Empty) || (it.ResellerId.HasValue && it.ResellerId != Guid.Empty)",
Message = "At least 1 CompanyId or ResellerId must be supplied"
)]
public class CreateIntegration : ICreateDb<Integration>, IReturn<IdResponse>
{
public Guid? CompanyId { get; set; }
public Guid? ResellerId { get; set; }
//.....
When I try to make the request I get error:
{
"responseStatus": {
"errorCode": "ScriptException",
"message": "ScriptContext has not been initialized. Call 'Init()' to initialize Script Context.",
"stackTrace": "ServiceStack.Script.ScriptException: ScriptContext has not been initialized. Call 'Init()' to initialize Script Context.\r\n ---> System.NotSupportedException: ScriptContext has not been initialized. Call 'Init()' to initialize Script Context.\r\n at ServiceStack.Script.PageResult.Init() in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Common/Script/PageResult.cs:line 436\r\n at ServiceStack.Script.PageResult.WriteToAsyncInternal(Stream outputStream, CancellationToken token) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Common/Script/PageResult.cs:line 281\r\n at ServiceStack.Script.PageResult.WriteToAsync(Stream responseStream, CancellationToken token) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Common/Script/PageResult.cs:line 244\r\n at ServiceStack.Script.ScriptContextUtils.EvaluateResultAsync(PageResult pageResult) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Common/Script/ScriptContext.cs:line 673\r\n --- End of inner exception stack trace ---\r\n at ServiceStack.Script.ScriptContextUtils.EvaluateResultAsync(PageResult pageResult) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Common/Script/ScriptContext.cs:line 681\r\n at ServiceStack.ServiceStackHost.EvalScriptAsync(PageResult pageResult, IRequest req, Dictionary`2 args) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/ServiceStackHost.cs:line 928\r\n at ServiceStack.ScriptValidator.IsValidAsync(Object dto, IRequest request) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/TypeValidators.cs:line 235\r\n at ServiceStack.TypeValidator.ThrowIfNotValidAsync(Object dto, IRequest request) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/TypeValidators.cs:line 312\r\n at ServiceStack.Validators.AssertTypeValidatorsAsync(IRequest req, Object requestDto, Type requestType) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Validators.cs:line 72\r\n at ServiceStack.Validation.ValidationFilters.RequestFilterAsync(IRequest req, IResponse res, Object requestDto, Boolean treatInfoAndWarningsAsErrors) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Validation/ValidationFilters.cs:line 27\r\n at ServiceStack.Validation.ValidationFilters.RequestFilterAsync(IRequest req, IResponse res, Object requestDto) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Validation/ValidationFilters.cs:line 15\r\n at ServiceStack.ServiceStackHost.ApplyRequestFiltersSingleAsync(IRequest req, IResponse res, Object requestDto) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/ServiceStackHost.Runtime.cs:line 216\r\n at ServiceStack.ServiceStackHost.ApplyRequestFiltersAsync(IRequest req, IResponse res, Object requestDto) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/ServiceStackHost.Runtime.cs:line 144\r\n at ServiceStack.Host.Handlers.GenericHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Host/Handlers/GenericHandler.cs:line 82\r\n\r\nSystem.NotSupportedException: ScriptContext has not been initialized. Call 'Init()' to initialize Script Context.\r\n at ServiceStack.Script.PageResult.Init() in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Common/Script/PageResult.cs:line 436\r\n at ServiceStack.Script.PageResult.WriteToAsyncInternal(Stream outputStream, CancellationToken token) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Common/Script/PageResult.cs:line 281\r\n at ServiceStack.Script.PageResult.WriteToAsync(Stream responseStream, CancellationToken token) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Common/Script/PageResult.cs:line 244\r\n at ServiceStack.Script.ScriptContextUtils.EvaluateResultAsync(PageResult pageResult) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Common/Script/ScriptContext.cs:line 673\r\n",
"errors": [],
"meta": {
"InnerMessages": "ScriptContext has not been initialized. Call 'Init()' to initialize Script Context."
}
}
}
I tried playing around with condition as it might not be valid #script but whatever I try I get the same error.
I do have some custom validators registered in apphost like:
ScriptContext.ScriptMethods.Add(new CogitoCustomScripts());
I have tried adding ScriptContext.Init()
in Configure
but I keep getting same error.
Where am I going wrong?