Search code examples
servicestackormlite-servicestack

MissingFieldException when querying a table with ServiceStack.OrmLite ServiceStack


I'm getting a MissingFieldException for multiple OrmLite operations:

using (var db = DbFactory.Open())
{
    var exp = db.From<Product>();

    if (filter.Field1 != null)
        exp.Where(w => w.Field1 == filter.Field1);

    if (filter.Field2 != null)
        exp.Where(w => w.Field2 == filter.Field2);

    return db.LoadSelect(exp);
}

Also occurs with a simple AutoQuery RDBMS service.

[Api("Query.")]
[Route(“/query, "GET")]
public class QueryTransaction : QueryDb<Transaction, TransactionQueryRecord>,
    IJoin<Transaction, Application>
{
    [ApiMember(IsRequired = false, ParameterType = "query")]
    public string TimeZoneId { get; set; }
}

The stack trace is the following:

System.MissingFieldException: Field not found: 'ServiceStack.OrmLite.OrmLiteConfig.UseParameterizeSqlExpressions'.
   at ServiceStack.OrmLite.SqlServer.SqlServerOrmLiteDialectProvider.SqlExpression[T]()
   at ServiceStack.OrmLite.OrmLiteExecFilter.SqlExpression[T](IDbConnection dbConn)
   at ServiceStack.OrmLite.OrmLiteReadExpressionsApi.From[T](IDbConnection dbConn)
   at ServiceStack.TypedQuery`2.CreateQuery(IDbConnection db, IQueryDb dto, Dictionary`2 dynamicParams, IAutoQueryOptions options)
   at ServiceStack.AutoQuery.CreateQuery[From,Into](IQueryDb`2 dto, Dictionary`2 dynamicParams, Request req

I think that OrmLite is trying to find the property configuration OrmLiteConfig.UseParameterizeSqlExpressions, but it doesn't exist in the version v.4.0.60

When I run my integration tests with AppSelfHostBase everything is ok, but when I try in the browser sometimes work and other times throw the exception.


Solution

  • Missing method or field exceptions like this is an indication that you're mixing and matching dirty .dlls with different versions together. OrmLiteConfig.UseParameterizeSqlExpressions was removed a while ago after OrmLite switched to use parameterized queries, this error indicates that you have an old .dll that references it.

    When you upgrade your ServiceStack projects you need to upgrade all dependencies and make sure all ServiceStack dependencies are referencing the same version (e.g v4.0.60 or the current latest v4.5.0). You can check the NuGet /packages folder to see the different versions your Solution uses. Deleting all but the latest version and rebuilding your solution will show build errors showing which projects were still referencing the older packages, which you'll want to update so that all projects are using the same version.