Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Native AOT deployment NET 8 #2694

Open
3 tasks done
LonerKO opened this issue Jun 7, 2023 · 4 comments
Open
3 tasks done

[Bug]: Native AOT deployment NET 8 #2694

LonerKO opened this issue Jun 7, 2023 · 4 comments

Comments

@LonerKO
Copy link

LonerKO commented Jun 7, 2023

Check The Docs

  • I double checked the docs and couldn't find any useful information.

Verify Issue Source

  • I verified the issue was caused by Discord.Net.

Check your intents

  • I double checked that I have the required intents.

Description

AOT deployment not works.

There are some bugs with JSON serialization and deserialization.

[Native-AOT] Using Json Serialize and Deserialize with Native AOT
dotnet/runtimelab#635

How to use source generation in System.Text.Json
https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation

Please add support for native AOT deployment.

Version

3.10.0

Working Version

Logs

Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type Discord.API.Rest.GetBotGatewayResponse. 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.
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader, JsonObjectContract, JsonProperty, JsonProperty, String, Boolean&) + 0x191
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader, Type, JsonContract, JsonProperty, JsonContainerContract, JsonProperty, Object) + 0x2ab
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader, Type, JsonContract, JsonProperty, JsonContainerContract, JsonProperty, Object) + 0xa4
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader, Type, Boolean) + 0x257
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader, Type) + 0xf3
   at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader) + 0x2f
   at Discord.API.DiscordRestApiClient.DeserializeJson[T](Stream) + 0x9a
   at Discord.API.DiscordRestApiClient.<SendAsync>d__73`1.MoveNext() + 0x17b
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb2
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x42
   at Discord.API.DiscordRestApiClient.<GetBotGatewayAsync>d__81.MoveNext() + 0x1d2
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb2
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x42
   at Discord.API.DiscordSocketApiClient.<ConnectInternalAsync>d__34.MoveNext() + 0x247
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
   at Discord.API.DiscordSocketApiClient.<ConnectInternalAsync>d__34.MoveNext() + 0x457
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb2
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x42
   at Discord.API.DiscordSocketApiClient.<ConnectAsync>d__33.MoveNext() + 0x1b0
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb2
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x42
   at Discord.WebSocket.DiscordSocketClient.<OnConnectingAsync>d__114.MoveNext() + 0x2fa
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb2
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x42
   at Discord.ConnectionManager.<ConnectAsync>d__31.MoveNext() + 0x5f0
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb2
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext() + 0x196

Sample

No response

Packages

Newtonsoft.Json - 13.0.3
Discord.Net - 3.10.0

@LonerKO LonerKO added the bug label Jun 7, 2023
@ivanjx
Copy link

ivanjx commented Jun 22, 2023

i don't think it will ever be possible unless this library uses STJ.
JamesNK/Newtonsoft.Json#2732

edit: too bad #2493

@Misha-133
Copy link
Member

i don't think it will ever be possible unless this library uses STJ.

v4 will use STJ as the default serializer.
will have to wait for now

@ivanjx
Copy link

ivanjx commented Jun 28, 2023

@Misha-133 really? there was a PR about STJ but it was closed.

@Misha-133
Copy link
Member

@Misha-133 really? there was a PR about STJ but it was closed.

Yeah, but it was targeting v3. V4 will have reworked REST implementation with support for STJ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants