Upgrading from ServiceStack 8.8.1 to 8.9.1 causes “Possible null reference” compilation errors:
// Compiles in 8.8.1
public class QueryDbRootService(IAutoQueryDb autoQuery) : Service
{
public QueryResponse<RootSummary> Get(SearchRootSummary request)
{
using var db = autoQuery.GetDb<RootSummary>(Request);
// Fails in 8.9.1
public class QueryDbRootService(IAutoQueryDb autoQuery) : Service
{
public QueryResponse<RootSummary> Get(SearchRootSummary request)
{
using var db = autoQuery.GetDb<RootSummary>(Request);
//Error CS8604 Possible null reference argument for parameter 'req' in 'IDbConnection IAutoQueryDb.GetDb<RootSummary>(IRequest req = null)'.
I did not find any breaking changes documented, so could you tell me how I can fix the error?
It’s only a compilation error because you’re treating nullable warnings as compilation errors.
Nullable annotations was enabled for the ServiceStack.Server library but seems like some annotations were missing. Should be resolved in the latest v8.9.1 in pre-release packages. You’ll need to clear your NuGet packages cache to download the latest v8.9.1:
I have cleared the nuget caches and performed restores, but I get the same error on different code now:
public class QueryDbRootService(IAutoQueryDb autoQuery) : Service
{
public QueryResponse<RootSummary> Get(SearchRootSummary request)
{
using var db = autoQuery.GetDb<RootSummary>(Request);
var q = autoQuery.CreateQuery(request, Request); // ERROR
//Possible null reference argument for parameter 'request' in 'SqlExpression<RootSummary> AutoQueryExtensions.CreateQuery<RootSummary>(IAutoQueryDb autoQuery, IQueryDb<RootSummary> model, IRequest request)'.
The only warning I see is for IRequest which is mandatory so you’ll need to use the ! null forgiving operator. IRequest is always populated in API Requests, but could be null in tests.
var q = autoQuery.CreateQuery(request, Request!, db);