C#C
C#12mo ago
6 replies
merlo17

Null reference exception

I am attempting to make a discord bot, and when I run a command like "?hello" I get a NullReferenceException. _commands was null.

So I attempted to fix it by initializing _commands in the startup by adding:
private CommandService _commands;
private IServiceProvider _services:

public async Task InitializeAsync()
{
    _commands = new CommandService();
    _services = new ServiceCollection()
        .AddSingleton(_commands)
        .BuildServiceProvider();

    await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services);
}


and then making sure to call the InitializeAsync() in the Main task. However, now I get error CS1503: Argument 1: cannot convert from System.Reflection.Assembly to System.Type.

I'm a little stumped on this and can't really find any details on what should be in place of Assembly.GetEntryAssembly()
image.png
Was this page helpful?