I’m getting a NullReferenceException inside MiniProfiler’s ProfiledDbCommand. Not sure if it’s a bug or something I’m doing wrong.
I’m opening a named connection, then using SqlProc and ConvertToList to return results from a stored procedure (as described here: https://github.com/ServiceStack/ServiceStack.OrmLite#stored-procedures-with-output-params)
My connection is registered like this:
dbFactory.RegisterConnection(“SomeNamedConnection”, new OrmLiteConnectionFactory(
ConfigurationManager.ConnectionStrings[“SomeConnectionString”].ConnectionString,
SqlServerDialect.Provider)
{
ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
});
Exception stack trace:
System.NullReferenceException: Object reference not set to an instance of an object.
at ServiceStack.MiniProfiler.Data.ProfiledDbCommand.get_CommandText()
at ServiceStack.OrmLite.OrmLiteCommand.get_CommandText()
at ServiceStack.OrmLite.OrmLiteResultsFilterExtensions.ConvertToList[T](IDbCommand dbCmd, String sql)
at UserRepository.GetUserIdsFromEmailAddresses(List`1 emailAddresses)
public List<int> GetUserIdsFromEmailAddresses(List<string> emailAddresses)
{
using (var someDb = dbFactory.OpenDbConnection(“SomeNamedConnection”))
{
return someDb
.SqlProc(“GetUserIdsFromEmailAddresses”, new { EmailAddresses = emailAddresses.Join(",") })
.ConvertToList<int>();
}
}
Yeah there was an issue with the IDbCommand being disposed before it was returned, it’s now fixed in v4.0.35 on MyGet (https://github.com/ServiceStack/ServiceStack/wiki/MyGet). Also you should change it to wrap it in a using statement, e.g:
https://github.com/ServiceStack/ServiceStack/blob/master/tests/Check.ServiceInterface/NamedConnectionService.cs
Uri Hendler:
Great, thanks.