- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在学习制作不和谐机器人的教程,在遵循了设置机器人的基础知识之后,我一直遇到这个异常:
已抛出 System.Reflection.TargetInvocationException。调用目标抛出异常。
这是我的代码:
using Discord.Commands;
using Discord;
using System;
namespace TestBot
{
public class MyBot
{
DiscordClient discord;
public MyBot()
{
discord = new DiscordClient(x =>
{
x.LogLevel = LogSeverity.Info;
x.LogHandler = Log;
});
discord.UsingCommands(x =>
{
x.PrefixChar = '!';
x.AllowMentionPrefix = true;
});
var commands = discord.GetService<CommandService>();
commands.CreateCommand("test")
.Do(async (e) =>
{
await e.Channel.SendMessage("response");
});
discord.ExecuteAndWait(async () =>
{
await discord.Connect("BOT_TOKEN", TokenType.Bot);
});
}
private void Log(object sender, LogMessageEventArgs e)
{
Console.WriteLine(e.Message);
}
}
}
MonoDevelop 说异常发生在这段代码中:
discord.ExecuteAndWait(async () =>
{
await discord.Connect("BOT_TOKEN", TokenType.Bot);
});
我不知道如何解决这个问题,所以非常感谢任何帮助。
(因为这是我在这里的第一篇文章,任何关于如何改进我的文章的建议也非常感谢。)
最佳答案
导致异常的真正原因被隐藏了。要解决此问题,您需要查看内部异常(如果需要,还需要查看该异常的内部异常等等)。这将让您看到问题的根本原因,并让您锻炼如何解决它。
当您的代码在 Debug模式下中断时,您可以查看内部异常;
单击“查看详细信息”可让您查看有关异常的更多信息;
一旦找到异常的真正原因,我建议您发布一个新问题,询问如何解决该特定问题(如果您自己无法解决)。
关于c# - 如何修复 "System.Reflection.TargetInvocationException has been thrown",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40066772/
更新 2:似乎这个库根本不支持 Compact-Framework,而且我不断收到其他异常 - 我将按原样离开这个问题,但我认为你不应该浪费时间回答它。 我 opened another questi
假设我有这个方法: MethodBuilder doubleMethod = typeBuilder.DefineMethod("Double",
我正在使用 Visual Studio 2008(C# Express Edition),我正在尝试调试由于我触发的事件而发生的 TargetInvocationException。 我的问题不是专门
我有一个名为carroms 的类(class)。当我创建它的对象时,没有错误。但是当我创建一个 carroms 数组时,抛出了这个异常: An unhandled exception of type
这个问题在这里已经有了答案: How to rethrow InnerException without losing stack trace in C#? (11 个答案) 关闭 8 年前。 我正
这个问题不太可能帮助任何 future 的访客;它只与一个小地理区域、一个特定时刻或一个非常狭窄的情况相关,而这些情况通常不适用于互联网的全局受众。如需帮助使这个问题更广泛地适用,visit the
由于 UI 线程(进度条)上的 Windows 控件,我在另一个线程中执行长时间处理时遇到了 TargetInvocationException。此异常导致我的应用程序崩溃(在调试中转到 main 方
我构建了一个显示图像的 WPF 控件。现在我想以非常快的速度更改该图像。我构建了一个 ImageContainer 类,它保存图像并有一个 ChangedEventHandler,它在更改时更新我控件
我收到这个未处理的异常错误: An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred
我想编写一个测试来检查我的抽象类构造函数是否正确处理了无效参数。我写了一个测试: [TestMethod] [ExpectedException(typeof(ArgumentException))]
我的调试器有问题,当在 UI 线程中执行错误代码时,调试器会正确指出错误行,这在线程内执行时也是如此,但在调度程序内调用时它的行为有点奇怪: TargetInvocationException 在反汇
我真的不知道发生了什么,为什么会一直发生 调用目标抛出异常。 代码在 frm5 中运行 然后错误显示在 程序.cs: using System; using System.Collections.Ge
我有许多使用 Delegate.DynamicInvoke 调用的方法。其中一些方法进行数据库调用,我希望能够捕获 SqlException 而不是捕获 TargetInvocationExcepti
我在使用反射实例化 DLL 文件中定义的类时遇到了一些问题。尽管代码看起来不错,但我在 Activator.CreateInstance 上得到了 TargetInvocationException。
解决方案后添加的注释:在反射调用的方法中抛出了 AccessViolationException。这就是无法捕获 TargetInvocationException 的原因。 注意:这是在 IDE 之
假设有以下情况。表单有一个按钮,单击该按钮可启动后台工作程序。在 RunWorkerCompleted 事件处理程序中,有一段代码会抛出未经处理的异常。表单从 Application.Run 方法启动
我正在为 Unity 游戏制作库存系统。 它按预期将库存序列化并保存到 xml 文件;但是,当我反序列化时,项目被设置为 null 并抛出 TargetInvocationException;最终是一
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 6 年前。 Improve
我正在开发 WPF 应用程序,但我仅在运行时在单个设备上收到此错误。 Exception Info: System.Reflection.TargetInvocationException 我的问题:
此异常是什么意思,我该如何解决? 最佳答案 来自 MSDN: The exception that is thrown by methods invoked through reflection. T
我是一名优秀的程序员,十分优秀!