ServiceStack 5.0 null reference when using FieldDefinition

We have code that alters db tables using AlterColumn or AddColumn and passing in FieldDefinition objects for the new fields. Upon upgrading to ServiceStack 5.0, we immediately began to see all of this code fail, with a null reference exception being throw inside of the ServiceStack.OrmLite code, inside the method GetColumnDefinition. Is this a known issue? Or maybe are we doing something wrong? We see it pretty consistently, in code that all used to run regularly and work before upgrading, and have had to downgrade back to v4.x while looking for a fix.

It’s not a known issue, please provide a stand-alone repro either we can run, e.g. on Gistlyn or GitHub.

Here is a very simple app that shows the problem. This code used to run.

The exception we get now looks like this (sorry I didn’t have the error anymore (after downgrading) and was a little imprecise about exactly what was going on in my OP):

Test method NullReferenceTest.NullReferenceTest.TestNullReference threw exception: 
System.NullReferenceException: Object reference not set to an instance of an object.
    at ServiceStack.PlatformExtensions.AllAttributes(PropertyInfo propertyInfo, Type attrType)
   at ServiceStack.OrmLite.MySql.MySqlDialectProviderBase`1.GetColumnDefinition(FieldDefinition fieldDef)
   at ServiceStack.OrmLite.OrmLiteDialectProviderBase`1.ToAlterColumnStatement(Type modelType, FieldDefinition fieldDef)
   at ServiceStack.OrmLite.OrmLiteSchemaModifyApi.AlterColumn(IDbConnection dbConn, Type modelType, FieldDefinition fieldDef)
   at NullReferenceTest.NullReferenceTest.TestNullReference() in C:\dev\NullReferenceTest\NullReferenceTest\NullReferenceTest.cs:line 35

Adding:

  1. We’re seeing the problem specifically with MySql. Haven’t tested on other db providers (we’re not using them).
  2. You’ll need to create a MySql schema and update the connection string in the App.Config to run this code.

The NRE was due to expecting the PropertyInfo for the field definition to be populated which is now being done null if not specified from this commit.

This change is available from v5.0.1 that’s now available on MyGet.

We assume that the fix you uploaded to Myget is in 5.0.2?? But in 5.0.2 we get the same issues.

2018-01-08 19:30:59.7044|Error|1|181|11

    [VenueMigrations.Migrations._41_AddDescriptionAndPersistToDiscoveredMessageCategory]: FAILED: [Migration <VenueMigrations.Migrations._41_AddDescriptionAndPersistToDiscoveredMessageCategory> FAILED: [System.NullReferenceException: Object reference not set to an instance of an object.
   at ServiceStack.PlatformExtensions.AllAttributes(PropertyInfo propertyInfo, Type attrType)
   at ServiceStack.OrmLite.MySql.MySqlDialectProviderBase`1.GetColumnDefinition(FieldDefinition fieldDef)
   at ServiceStack.OrmLite.OrmLiteDialectProviderBase`1.ToAddColumnStatement(Type modelType, FieldDefinition fieldDef)
   at ServiceStack.OrmLite.OrmLiteSchemaModifyApi.AddColumn(IDbConnection dbConn, Type modelType, FieldDefinition fieldDef)
   at VenueMigrations.Migrations._41_AddDescriptionAndPersistToDiscoveredMessageCategory.<>c__DisplayClass2_0.<Up>b__0() in C:\dev\ServerStandalone\VenueMigrations\Migrations\_41_AddDescriptionAndPersistToDiscoveredMessageCategory.cs:line 25
   at VenueMigrationService.Migration.Run(Action migrationAction) in C:\dev\ServerStandalone\VenueMigrationService\Migration.cs:line 20]]

This is the code

                db.AddColumn(typeof(DiscoveredMessageCategory), new FieldDefinition()
                {
                    FieldType = typeof(bool),
                    Name = "Persist",
                });

Im going to downgrade in an hour or so. But is there anything I should try to change in this code?

Looks like this is a new issue. since the first post was this line.

at ServiceStack.OrmLite.OrmLiteSchemaModifyApi.AlterColumn(IDbConnection dbConn, Type modelType, FieldDefinition fieldDef)

and this one is

at ServiceStack.OrmLite.OrmLiteSchemaModifyApi.AddColumn(IDbConnection dbConn, Type modelType, FieldDefinition fieldDef)

The version on MyGet always ends with an odd number, the latest version being v5.0.3. But v5.0.2 on NuGet does have the fix as per the integration test.

This is a separate issue from adding a column when the property doesn’t exist on the table which should be resolved from this commit. This change is available from v5.0.3 that’s now available on MyGet.