On .Net Framework 4.8, servicestack 6.2 and StackExchange.MiniProfiler 4.2.22, when an async call is made, it blows up with
Unable to cast object of type 'StackExchange.Profiling.Data.ProfiledDbCommand' to type 'Npgsql.NpgsqlCommand'.
I’ve created a small gist with repro at https://gist.github.com/brunomlopes/0ab96c0b675eaaf46f98373c8136a499.
From https://github.com/MiniProfiler/dotnet/issues/519 it seems to be an assumption with SS.
The basic code is:
[Fact]
public async Task Test()
{
var connectionFactory = CreateConnectionFactoryFactory();
using (var db = connectionFactory.OpenDbConnection())
{
var query = "select @category as Category";
var d = (await db.SelectAsync<Result>(query, new { category = "some text"}))
.ToArray();
Assert.NotEmpty(d);
Assert.Equal("some text", d[0].Category);
}
}
private static OrmLiteConnectionFactory CreateConnectionFactoryFactory()
{
string sqlConnectionString =
"Server=localhost;Port=5432;User Id=postgres;Database=postgres";
return new OrmLiteConnectionFactory(sqlConnectionString, PostgreSqlDialect.Provider)
{
ConnectionFilter = connection =>
{
// This forces a specific datestyle when communicating with PGSQL, and ensures that we
// use our datetime format even if the database has a separate format.
connection.ExecuteNonQuery(@"SET datestyle TO ""ISO, DMY""");
return new ProfiledDbConnection((DbConnection) connection, MiniProfiler.Current);
}
};
}
Is this a bug?