I upgraded from ServiceStack 6.0.1 to the latest 6.3.1.
I now have a System.ArgumentException: Delegate to an instance method cannot have null ‘this’
It is being caused by my previously working 6.0.1 code:
//InvoiceService.cs
using var db = AutoQuery!.GetDb<Invoice>(Request);
var query = new ReadInvoice { InvoiceNumber = invoice.InvoiceNumber };
var q = AutoQuery.CreateQuery(query, Request, db);
var finds = AutoQuery.Execute(query, q, Request, db); // error caused here on line 112
Stepping through the stack trace, it seems that the problem is that refModelDef is null in this method:
//ServiceStack.OrmLite.OrmLiteReadCommandExtensions.cs
public static FieldDefinition GetSelfRefFieldDefIfExists(this ModelDefinition modelDef, ModelDefinition refModelDef, FieldDefinition fieldDef)
{
var refField = (fieldDef == null ? null
: modelDef.FieldDefinitions.FirstOrDefault(x => x.ForeignKey != null && x.ForeignKey.ReferenceType == refModelDef.ModelType
&& fieldDef.IsSelfRefField(x)))
?? modelDef.FieldDefinitions.FirstOrDefault(x => x.ForeignKey != null && x.ForeignKey.ReferenceType == refModelDef.ModelType)
?? modelDef.FieldDefinitions.FirstOrDefault(refModelDef.IsRefField);
return refField;
}
The stack trace was:
System.ArgumentException: Delegate to an instance method cannot have null 'this'.
---> System.ArgumentException: Delegate to an instance method cannot have null 'this'.
at System.MulticastDelegate.ThrowNullThisInDelegateToInstance()
at System.MulticastDelegate.CtorClosed(Object target, IntPtr methodPtr)
at ServiceStack.OrmLite.OrmLiteReadCommandExtensions.GetSelfRefFieldDefIfExists(ModelDefinition modelDef, ModelDefinition refModelDef, FieldDefinition fieldDef) in
/home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteReadCommandExtensions.cs:line 1030
at ServiceStack.OrmLite.Support.LoadListSync`2.SetRefField(FieldDefinition fieldDef, Type refType) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/Support/LoadList.cs:line 257
at ServiceStack.OrmLite.OrmLiteReadCommandExtensions.LoadListWithReferences[Into,From](IDbCommand dbCmd, SqlExpression`1 expr, IEnumerable`1 include) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteReadCommandExtensions.cs:line 1002
at ServiceStack.OrmLite.ReadExpressionCommandExtensions.LoadSelect[Into,From](IDbCommand dbCmd, SqlExpression`1 expression, IEnumerable`1 include) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/Expressions/ReadExpressionCommandExtensions.cs:line 237
at ServiceStack.OrmLite.OrmLiteReadExpressionsApi.<>c__DisplayClass65_0`2.<LoadSelect>b__0(IDbCommand dbCmd) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteReadExpressionsApi.cs:line 435
at ServiceStack.OrmLite.OrmLiteExecFilter.Exec[T](IDbConnection dbConn, Func`2 filter) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteExecFilter.cs:line 66
at ServiceStack.OrmLite.OrmLiteReadExpressionsApi.Exec[T](IDbConnection dbConn, Func`2 filter) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteReadExpressionsApi.cs:line 18
at ServiceStack.OrmLite.OrmLiteReadExpressionsApi.LoadSelect[Into,From](IDbConnection dbConn, SqlExpression`1 expression, IEnumerable`1 include) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteReadExpressionsApi.cs:line 435
at ServiceStack.TypedQuery`2.Execute[Into](IDbConnection db, ISqlExpression query) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Server/AutoQueryFeature.cs:line 1699
--- End of inner exception stack trace ---
at ServiceStack.TypedQuery`2.Execute[Into](IDbConnection db, ISqlExpression query) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Server/AutoQueryFeature.cs:line 1709
at ServiceStack.AutoQuery.Execute[From](IQueryDb`1 model, SqlExpression`1 query, IRequest req, IDbConnection db) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Server/AutoQueryFeature.cs:line 1031
at ServiceInterface.InvoiceNs.InvoiceService.GetNewInvoices(List`1 values) in C:\Tmp\ServiceInterface\InvoiceNs\InvoiceService.cs:line 112
Do I need to adjust my code elsewhere for 6.3.1?