找不到默认的TypeReader,必须指定一个.net Core

时间:2017-02-25 15:02:53

标签: .net core

我正在尝试运行.net Core控制台应用程序。在我实现了以下代码之后,它抛出了这个异常:

var database = new Database("tokens");
var tokens = database.FireCommand("SELECT * FROM tokens");

var tokensList = new List<object>();

while (tokens.Read())
{
    var userId = (string)tokens["user_id"];
    var userName = (string)tokens["username"];
    var tokenAmount = (int)tokens["tokens"];

    tokensList.Add(new { userId = userId, username = userName, tokens = tokenAmount });
}

database.CloseConnection();

例外:     找不到默认的TypeReader,必须指定一个

如何解决此问题/指定TypeReader?

编辑:

    public Database(string table)
    {
        this.table = table;
        MySqlConnectionStringBuilder stringBuilder = new MySqlConnectionStringBuilder();
        stringBuilder.Server = server;
        stringBuilder.UserID = username;
        stringBuilder.Password = password;
        stringBuilder.Database = database;

        var connectionString = stringBuilder.ToString();

        dbConnection = new MySqlConnection(connectionString);

        dbConnection.Open();
    }

    public MySqlDataReader FireCommand(string query)
    {
        if(dbConnection == null)
        {
            return null;
        }

        MySqlCommand command = new MySqlCommand(query, dbConnection);

        var mySqlReader = command.ExecuteReader();

        return mySqlReader;
    }

    public void CloseConnection()
    {
        if(dbConnection != null)
        {
            dbConnection.Close();
        }
    }

堆栈跟踪

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Private.CoreLib.ni.dll

Additional information: No default TypeReader found, one must be specified
           at Discord.Commands.Builders.ParameterBuilder.Build(CommandInfo info)
       at System.Linq.Enumerable.SelectListIterator`2.ToArray()
       at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
       at Discord.Commands.CommandInfo..ctor(CommandBuilder builder, ModuleInfo module, CommandService service)
       at Discord.Commands.Builders.CommandBuilder.Build(ModuleInfo info, CommandService service)
       at System.Linq.Enumerable.SelectListIterator`2.ToArray()
       at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
       at Discord.Commands.ModuleInfo..ctor(ModuleBuilder builder, CommandService service, ModuleInfo parent)
       at Discord.Commands.Builders.ModuleBuilder.BuildImpl(CommandService service, ModuleInfo parent)
       at Discord.Commands.ModuleClassBuilder.Build(IEnumerable`1 validTypes, CommandService service)
       at Discord.Commands.CommandService.<AddModulesAsync>d__20.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at DiscordExampleBot.CommandHandler.<Install>d__3.MoveNext() in C:\Users\Jannik\Documents\Visual Studio 2015\Projects\DiscordDotNet1_0\src\DiscordDotNet1_0\CommandHandler.cs:line 23
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at DiscordExampleBot.Program.<Start>d__5.MoveNext() in C:\Users\Jannik\Documents\Visual Studio 2015\Projects\DiscordDotNet1_0\src\DiscordDotNet1_0\Program.cs:line 35
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at DiscordExampleBot.Program.Main(String[] args) in C:\Users\Jannik\Documents\Visual Studio 2015\Projects\DiscordDotNet1_0\src\DiscordDotNet1_0\Program.cs:line 15

0 个答案:

没有答案