我正在使用.net核心,并试图使asp.net核心+ mysql + dapper + mini-mvc-profiler在Linux上工作。 mini-mvc-profiler有问题。

我在用着:

<PackageReference Include="Dapper" Version="1.50.2" />
<PackageReference Include="MiniProfiler.AspNetCore" Version="4.0.0-alpha6-79" />
<PackageReference Include="MiniProfiler.Shared" Version="4.0.0-alpha6-79" />
<PackageReference Include="MySql.Data.Core" Version="7.0.4-IR-191" />


我有SQLProfiler类:

public class SQLProfiler
{
    public static DbConnection GetOpenConnection(string connectionString)
    {
        //return new MySqlConnection(connectionString); // that works OK
        return new StackExchange.Profiling.Data.ProfiledDbConnection(
            new MySqlConnection(connectionString), MiniProfiler.Current
        );
    }
}


并从存储库类调用它:

using (var connection = SQLProfiler.GetOpenConnection(_connectionString))
{
    return connection.Query<UserIdentityDTO>(sql,
        new {
            myemail = email,
            mypassword = password,
            myprovider = PROVIDER_LOCAL
        }
    ).FirstOrDefault();
}


我得到:

NullReferenceException: Object reference not set to an instance of an object.
MySql.Data.MySqlClient.MySqlConnection.set_Reader(MySqlDataReader value)


堆栈跟踪:

MySql.Data.MySqlClient.MySqlConnection.set_Reader(MySqlDataReader value)
MySql.Data.MySqlClient.MySqlCommand.ResetReader()
MySql.Data.MySqlClient.MySqlCommand.Dispose(bool disposing)
StackExchange.Profiling.Data.ProfiledDbCommand.Dispose(bool disposing) in ProfiledDbCommand.cs
System.Data.Common.DbCommand.Dispose()
Dapper.SqlMapper+<QueryImpl>d__124.MoveNext()
System.Collections.Generic.List..ctor(IEnumerable<T> collection)
System.Linq.Enumerable.ToList<TSource>(IEnumerable<TSource> source)
Dapper.SqlMapper.Query<T>(IDbConnection cnn, string sql, object param, IDbTransaction transaction, bool buffered, Nullable<int> commandTimeout, Nullable<CommandType> commandType)
persistance.dapper.repository.UserQueries.Get(string email, string password) in UserQueries.cs

最佳答案

正如尼克·克雷弗(Nick Craver)所建议的,

 <ItemGroup>
    <PackageReference Include="Dapper" Version="1.50.2" />
    <PackageReference Include="DapperExtensions.DotnetCore" Version="1.0.1" />
    <PackageReference Include="MiniProfiler.AspNetCore" Version="4.0.0-alpha6-79" />
    <PackageReference Include="MiniProfiler.Shared" Version="4.0.0-alpha6-79" />
    <PackageReference Include="MySqlConnector" Version="0.30.0" />
  </ItemGroup>


...它还活着 :-)

10-05 21:23
查看更多