DSharpPlus / DSharpPlus

A .NET library for making bots using the Discord API.
https://discord.gg/dsharpplus
MIT License
1.24k stars 304 forks source link

No support for native AOT compilation #1637

Open migueloliveiradev opened 1 year ago

migueloliveiradev commented 1 year ago

Describe the bug

When trying to do a Native AOT compilation using .NET 7 or .NET 8 I receive an error

bot-fy  | [2023-10-02 18:50:02 -03:00] [102 /ConnectionFa] [Error] Connection attempt failed, retrying in 7s
bot-fy  | Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type DSharpPlus.Net.GatewayInfo. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'url', line 1, position 7.
bot-fy  |    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader, JsonObjectContract, JsonProperty, JsonProperty, String, Boolean&) + 0x17b
bot-fy  |    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader, Type, JsonContract, JsonProperty, JsonContainerContract, JsonProperty, Object) + 0x2be
bot-fy  |    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader, Type, JsonContract, JsonProperty, JsonContainerContract, JsonProperty, Object) + 0x9e
bot-fy  |    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader, Type, Boolean) + 0x24a
bot-fy  |    at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader, Type) + 0x108
bot-fy  |    at Newtonsoft.Json.Linq.JToken.ToObject(Type, JsonSerializer) + 0xaf
bot-fy  |    at Newtonsoft.Json.Linq.JToken.ToObject[T](JsonSerializer) + 0x2d
bot-fy  |    at DSharpPlus.Net.DiscordApiClient.<GetGatewayInfoAsync>d__184.MoveNext() + 0x3b6
bot-fy  | --- End of stack trace from previous location ---
bot-fy  |    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
bot-fy  |    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xc2
bot-fy  |    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x44
bot-fy  |    at DSharpPlus.BaseDiscordClient.<GetGatewayInfoAsync>d__36.MoveNext() + 0x430
bot-fy  | --- End of stack trace from previous location ---
bot-fy  |    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
bot-fy  |    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xc2
bot-fy  |    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x44
bot-fy  |    at DSharpPlus.DiscordClient.<InternalUpdateGatewayAsync>d__505.MoveNext() + 0xbc
bot-fy  | --- End of stack trace from previous location ---
bot-fy  |    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
bot-fy  |    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xc2
bot-fy  |    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x44
bot-fy  |    at DSharpPlus.DiscordClient.<InternalConnectAsync>d__493.MoveNext() + 0x71b
bot-fy  | --- End of stack trace from previous location ---
bot-fy  |    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
bot-fy  |    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xc2
bot-fy  |    at DSharpPlus.DiscordClient.<ConnectAsync>d__46.MoveNext() + 0x57b

While doing some investigation, I noticed an incompatibility of the Newtonsoft.Json library, which mentioned by the library owner, such support is unlikely

I decided to leave this issue because maybe in v6 System.Text.Json could be used

akiraveliara commented 1 year ago

STJ is being used, but NAOT is a lot of work regardless and will probably not have complete support even through v6 - it's possible, but i recommend not getting your hopes up.

migueloliveiradev commented 1 year ago

Ok