#System.NullReferenceException on DiscordWebhook.ExecuteAsync

1 messages · Page 1 of 1 (latest)

somber tinsel
#

Hi everyone.

Since plurial days, i'll send hooks with somes bots, but System.NullReferenceException is catched.

There's the used method:

public static async Task SendHook(DiscordChannel c, HookInfo h, string Message)
        {
            try
            {
                DiscordWebhook? Hook = null;
                var Hooks = await c.GetWebhooksAsync();
                foreach (DiscordWebhook H in Hooks)
                    if (H.Name == "OzBot") Hook = H;
                if (Hook is null) Hook = await c.CreateWebhookAsync("OzBot");

                DiscordWebhookBuilder b = new DiscordWebhookBuilder()
                {
                    AvatarUrl = h.AvatarURL,
                    Username = h.NickName,
                    Content = Message
                };

                await Hook.ExecuteAsync(b);
            } catch (Exception ex) { await Logs.CatchedEventException(c, ex, $"Messaging.SendHook"); }
        }

For information, HookInfo is stocking AvatarURL, NickName and who is allowed to use this hook info, I'll just use AvatarURL and NickName for sending.

The exception is catched at await Hook.ExecuteAsync(b); and it were work before.

StackTrace :

ERREUR :
System.NullReferenceException
Object reference not set to an instance of an object.

STACKTRACE:
   at DSharpPlus.Net.RestClient.GetBucket(RestRequestMethod method, String route, Object route_params, String& url)
   at DSharpPlus.Net.DiscordApiClient.ExecuteWebhookAsync(UInt64 webhook_id, String webhook_token, DiscordWebhookBuilder builder)
   at Barmaid.Libs.Messaging.SendHook(DiscordChannel c, HookInfo h, String Message) in F:\OneDrive\Documents\Sources\Barmaid\Barmaid3\Libs\Messaging.cs:line 110

Anyone having idea ?

PS : Lib is up to date.

rough spire
#

can you set the LogLevel in your client and see what logs appear when you call the ExecuteAsync method

#

(don't post full trace logs here, they will contain the bots user token in plaintext)

somber tinsel
#

I've set loglevel to Debug and it works

#

I don't catch the exception with LogLevel.Debug

somber tinsel
#

Ah. On local it's work, but not on prod...

somber tinsel
rough spire
#

yea sorry

#

set it to Trace

somber tinsel
# rough spire set it to Trace

I tried in Trace, and I don't see what can help to correct this, to tell the truth the logs are incomprehensible. What exactly should I look for?

rough spire
#

wait until they settle down, then trigger that method

#

what you see are the gateway & REST packets

somber tinsel
#

Note: it works for me in pre-prod this time, but as soon as I go into prod (Windows Server 2019), I get the exception.

rough spire
#

i just want to understand if you can send the webhook request

#

aaah

#

seems like a runtime issue?

somber tinsel
#

I'll check to see if I have any updates.

#

Found an .NET update which is not installed. I'll update it now.

rough spire
#

thats .net framework

#

dont tell me you use .net framework

somber tinsel
#

Huh, i read it's for .NET Framework, my bot is .NET Core.

#

So, nope ! XD

rough spire
#

thank god

somber tinsel
#

I use .NET core 6

rough spire
#

if you cant see it before the message gets through its definitely a lib issue

somber tinsel
rough spire
#

basically

somber tinsel
#

I send it to you in DM ?

rough spire
#

by here i mean the internet

somber tinsel
#

I don't see any token, i think

rough spire
#

scroll way up

somber tinsel
#

There is no token from command call to the exception

rough spire
#

oh yeah that part is safe

somber tinsel
#

I'll send it to you ? I checked there is no token

rough spire
#

if you cannot find the message content there, it wont change anything

somber tinsel
#

I caugh the original message containing the call command, but between it to the exception, there is no messages sended - except a message to alert me to the error

#

If i try to reboot the server...?

rough spire
#

probably wouldnt change anyting

#

you could try to use the debugger & get into the d#+ code to see where it goes wrong

somber tinsel
#

As we said in France :

Dans le doute, reboot !
translate as When in doubt, reboot

#

Debugger is not installed on the server

rough spire
#

oh right you did mention that it doesnt happen in the dev env

somber tinsel
#

Not since I set LogLevel to Debug. xD

#

Before, I had the error too

#

Is that magical ?

#

Well, still the error

#

this stuff is driving me crazy