Search code examples
servicestackormlite-servicestack

NullReference Exception in ConvertToList (ServiceStack OrmLite)


I am using OrmLite for data access in an application. Everything is working as expected in 3 of 4 environments.

All environments are running .net 4.5. The databases are running different versions. The failing environment is connecting to sql server 10.50.2796, the working environments are connecting to sql server 10.50.4000.

The versions of the System.Data* assemblies are the same on the server that isn't working.

Stacktrace:

System.NullReferenceException: Object reference not set to an instance of an object. at lambda_method(Closure , Object , Object ) at ServiceStack.OrmLite.ReadExtensions.ConvertToList[T](IDataReader dataReader) in C:\src\ServiceStack.OrmLite\src\ServiceStack.OrmLite\Expressions\ReadExtensions.cs:line 151 at ServiceStack.OrmLite.ReadExtensions.Select[T](IDbCommand dbCmd, Expression1 predicate) in C:\src\ServiceStack.OrmLite\src\ServiceStack.OrmLite\Expressions\ReadExtensions.cs:line 23 at ServiceStack.OrmLite.ReadConnectionExtensions.Exec[T](IDbConnection dbConn, Func2 filter) in C:\src\ServiceStack.OrmLite\src\ServiceStack.OrmLite\Expressions\ReadConnectionExtensions.cs:line 26

UPDATE I think this is a bug related to the version of sql server I am connecting to. If I change the connection string in the working environment to use the database running 10.50.2796 I experience the same error.

TIA, jason


Solution

  • This bug occurred b/c fields in the database contained nulls, and the corresponding model fields weren't nullable. I will try and dig a bit deeper and provide some tests to the OrmLite team. The DB version was a red herring.