sendToAutoQuery Raises Exception

Hello,

I am trying to use a AutoQuery service from the #servicestack:sharp-script page using sendToAutoQuery. It gives me the below exception. If I call the route /api/categories it works with filters and all.

Thanks,
Amit.

Service definition:

[Route("/api/categories")]
public class QueryCategory : QueryDb<Category>
{
}

Calling code:

{{ sendToAutoQuery({namecontains: "Moth"}, 'QueryCategory') |> htmlDump }}

Exception:

StopFilterExecutionException: StopFilterExecutionException
   at ServiceStack.ServiceStackScripts.sendToAutoQuery(ScriptScopeContext scope, Object dto, String requestName, Object options) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\ServiceStackScripts.cs:line 252
   at lambda_method229(Closure , Object , Object[] )
   at ServiceStack.Script.PageResult.InvokeFilter(MethodInvoker invoker, ScriptMethods filter, Object[] args, String binding) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Common\Script\PageResult.cs:line 1041
   at ServiceStack.Script.JsCallExpression.Evaluate(ScriptScopeContext scope) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Common\Script\JsCallExpression.cs:line 241
   at ServiceStack.Script.PageResult.EvaluateAsync(PageVariableFragment var, ScriptScopeContext scope, CancellationToken token) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Common\Script\PageResult.cs:line 684
   at ServiceStack.Script.PageResult.WriteVarAsync(ScriptScopeContext scope, PageVariableFragment var, CancellationToken token) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Common\Script\PageResult.cs:line 655
   at ServiceStack.Script.ScriptTemplate.WritePageFragmentAsync(ScriptScopeContext scope, PageFragment fragment, CancellationToken token) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Common\Script\ScriptLanguage.Template.cs:line 83
   at ServiceStack.Script.PageResult.WritePageFragmentAsync(ScriptScopeContext scope, PageFragment fragment, CancellationToken token) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Common\Script\PageResult.cs:line 376
   at ServiceStack.Script.PageResult.WriteFragmentsAsync(ScriptScopeContext scope, IEnumerable`1 fragments, String callTrace, CancellationToken token) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Common\Script\PageResult.cs:line 363
   at ServiceStack.Script.PageResult.WritePageAsyncInternal(SharpPage page, ScriptScopeContext scope, CancellationToken token) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Common\Script\PageResult.cs:line 567
   at ServiceStack.Script.PageResult.WritePageAsync(SharpPage page, ScriptScopeContext scope, CancellationToken token) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Common\Script\PageResult.cs:line 537
   at ServiceStack.Script.ScriptTemplate.WritePageFragmentAsync(ScriptScopeContext scope, PageFragment fragment, CancellationToken token) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Common\Script\ScriptLanguage.Template.cs:line 83
   at ServiceStack.Script.PageResult.WritePageFragmentAsync(ScriptScopeContext scope, PageFragment fragment, CancellationToken token) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Common\Script\PageResult.cs:line 376
   at ServiceStack.Script.PageResult.WriteToAsyncInternal(Stream outputStream, CancellationToken token) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Common\Script\PageResult.cs:line 343
   at ServiceStack.Script.PageResult.WriteToAsync(Stream responseStream, CancellationToken token) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Common\Script\PageResult.cs:line 250
   at ServiceStack.SharpPageHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\SharpPagesFeature.cs:line 973

Inner Exceptions:
NotImplementedException: sendToAutoQuery RDBMS requires TemplateAutoQueryFilters
   at ServiceStack.ServiceStackScripts.sendToAutoQuery(ScriptScopeContext scope, Object dto, String requestName, Object options) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\ServiceStackScripts.cs:line 216

The InnerException contains the cause of the issue:

Update:

TemplateAutoQueryFilters was the old name, to use AutoQuery Script Methods the AutoQueryScripts from the ServiceStack.Server NuGet packages which contains the AutoQuery implementation, needs to be registered, e.g:

Plugins.Add(new SharpPagesFeature {
    ScriptMethods = { new AutoQueryScripts() },
});

Note: So it gets properly formatted, when pasting C# code add them between:

```csharp
//C# code here
```

For #Script code you can paste it with Handle bars syntax:

```hbs
{{ fn(arg) }}
```

For Exception StackTraces you can either indent them 4 spaces or wrap them in vanilla triple quotes so they’re shown in an easier to read pre-formatted mono space font, e.g:

````
Exception StackTrace
````

Thanks for the tip for proper formatting.

            Plugins.Add(new SharpPagesFeature()
            {
                ScanAssemblies = new List<Assembly>{Assembly.GetExecutingAssembly()},
                RenderExpressionExceptions = true
            }); // enable server-side rendering, see: https://sharpscript.net/docs/sharp-pages

The #script page is just a simple html page with that single line.

Thanks, actually to use AutoQuery RDBMS #Script Methods you need to register AutoQueryScripts from ServiceStack.Server NuGet package, e.g:

Plugins.Add(new SharpPagesFeature {
    ScriptMethods = { new AutoQueryScripts() },
});

Thanks a lot and awesome as always for your quick help. This resolved the issue.

1 Like