How to fix "System.Reflection.TargetInvocationException has been thrown"
bots, c#
Solution
The true cause for your exception is being hidden from you. To fix this issue you will need to view the inner exception (and if required the inner exception of that exception and so on..). This will allow you to see the root cause of the issue and allow you to workout how to fix it.
You can view the inner exception when your code breaks in debug mode;
Clicking view detail will allow you to see more information about your exception;
Once you get to the true cause of your exception I suggest you post a new question asking how to solve that specific issue (if you can't solve it yourself).
Problem
I'm following a tutorial for making a discord bot, and after following the basics for setting up a bot I keep running into this exception: System.Reflection.TargetInvocationException has been thrown. Exception has been thrown by the target of an invocation. This is the code I have: ``` 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 says that the exception is happening with this piece of code: ``` discord.ExecuteAndWait(async () => { await discord.Connect("BOT_TOKEN", TokenType.Bot); }); ``` I don't know how to fix this, so any help would be greatly appreciated. (As this is my first post here, any suggestions on how to improve my posts are also appreciated.)