Intermittent (Null Reference Exception)

we have the following stack trace at the bottom. This error occur in an intermittent matter on our production server and we cannot reproduce it on our dev. environment.

From the code below when we hit the Db.Insert(). We have that loop cause it kind of an ETL process. This is at the end of the process and we have validate all our fields from all the rows so we are ready to insert. but we want to log the line in error if the DB reject it.

        // Save each record from the spreadsheet to the db
        foreach (BusinessUnitProductCost bupc in result.BusinessUnitProductCosts)
            catch (SqlException ex)
                result.Messages.Add($"Unable to save new record to the database. {ex.Message}");

Just curious if you saw that kind of exception before…

“ResponseStatus”:{“ErrorCode”:“NullReferenceException”,“Message”:“Object reference not set to an instance of an object.”,“StackTrace”:"[LoadBusinessUnitProductCostRequest: 2020-03-27 6:25:19 PM]:\n[REQUEST: {FileName:Copy of 3172020101441_Actuals 2019_2085 20200311 v2.xlsx,UserEntity:104,UserName:lzolotareva,Version:actuals,FiscalYear:2019,BUnitCd:2085}]\nSystem.NullReferenceException: Object reference not set to an instance of an object.\r\n at System.Object.GetType()\r\n at ServiceStack.OrmLite.OrmLiteDialectProviderBase1.GetAnonValue(FieldDefinition fieldDef, Object obj)\r\n at ServiceStack.OrmLite.OrmLiteDialectProviderBase1.GetValue[T](FieldDefinition fieldDef, Object obj)\r\n at ServiceStack.OrmLite.OrmLiteDialectProviderBase1.GetValueOrDbNull[T](FieldDefinition fieldDef, Object obj)\r\n at ServiceStack.OrmLite.OrmLiteDialectProviderBase1.SetParameterValue[T](FieldDefinition fieldDef, IDataParameter p, Object obj)\r\n at ServiceStack.OrmLite.OrmLiteDialectProviderBase1.SetParameterValues[T](IDbCommand dbCmd, Object obj)\r\n at ServiceStack.OrmLite.OrmLiteWriteCommandExtensions.Insert[T](IDbCommand dbCmd, T obj, Action1 commandFilter, Boolean selectIdentity)\r\n at ServiceStack.OrmLite.OrmLiteWriteApi.<>c__DisplayClass5_01.<Insert>b__0(IDbCommand dbCmd)\r\n at ServiceStack.OrmLite.OrmLiteExecFilter.Exec[T](IDbConnection dbConn, Func2 filter)\r\n at CogLoadServiceInterface.BusinessUnitProductCostService.Put(LoadBusinessUnitProductCostRequest request) in I:\TFS_Agent01\_work\30\s\CogLoadServiceInterface\TM1\BusinessUnitProductCostService.cs:line 99\r\n at ServiceStack.Host.ServiceRunner`1.d__15.MoveNext()",“Errors”:[]


I’ll need a minimal repro I can locally to be able to investigate, otherwise you can try upgrading to the latest v5.8.1 on MyGet as there’s been some changes to those APIs.