I found when calling a stored procedure that has a DbString property and that instance is null, a NullReference exception is thrown.
Unhandledexception. System.NullReferenceException: Objectreferencenotsettoaninstanceofanobject.
atParamInfo5dd7247d-fd49-42a6-8b6e-f45fb45c461e(IDbCommand , Object )
atDapper.CommandDefinition.SetupCommand(IDbConnectioncnn, Action`2 paramReader)atDapper.SqlMapper.ExecuteCommand(IDbConnectioncnn, CommandDefinition& command, Action`2 paramReader)atDapper.SqlMapper.ExecuteImpl(IDbConnectioncnn, CommandDefinition& command)
atDapper.SqlMapper.Execute(IDbConnectioncnn, Stringsql, Objectparam, IDbTransactiontransaction, Nullable`1 commandTimeout, Nullable`1commandType)
atConsoleApp1.Program.Main(String[] args)
Example:
using(varconn=newSqlConnection(connString)){DbStringnullDbString=null;varparameterObject=new{Value1=nullDbString,};conn.Execute("Test_Insert",parameterObject,null,null,CommandType.StoredProcedure);}I bumped into this due to code that looked something like:
publicclassModel{publicstringValue{get;set;}}publicclassModel2{publicModelInstance{get;set;}}publicstaticclassExtensions{publicstaticDbStringToDbString(thisstringvalue){returnnewDbString(){Value=value};}}varmodel2=newModel2();model2.Instance=null;//null due to a missing model in a json payload or somethingusing(varconn=newSqlConnection(connString)){varp=new{Value1=model2?.Instance?.Value,//this is fineValue2=model2?.Instance?.Value?.ToDbString()//this causes a null ref to be thrown};conn.Execute("Test_Insert",p,null,null,CommandType.StoredProcedure);}I would expect the same behavior as passing a null string - a conversion to DbNull.Value.
I found when calling a stored procedure that has a DbString property and that instance is null, a NullReference exception is thrown.
Example:
I bumped into this due to code that looked something like:
I would expect the same behavior as passing a null string - a conversion to DbNull.Value.