Blazor Web Assembly - error while creating DiscordSocketClient.
See original GitHub issueIssue
I can’t get Discord.Net to work in Blazor WebAssembly app. Error occurs every time after trying to create new instance of DiscordSocketClient(). It worked with server-side Blazor application.
I’m using new web assembly template provided in Visual Studio.
My suspicions
I suspect this may be occurring because WebAssembly app is using .net standard 2.1 in project instead of .net core 3.1 (my previous project with server side Blazor worked on .net core 3.1 and it worked with no problem) or because Blazor WASM is using other runtime. Unfortunately every time I try to change project settings Blazor WASM just doesn’t work. (couldn’t found any solution online for this, only fact that it runs in mono: https://stackoverflow.com/questions/61170445/blazor-webassembly-3-1-target-framework-is-missing).
Also, log below shows that Automatic Decompression is not supported, so maybe I’ll need to bypass this somehow. If anybody know some quick fix for this, I’d be very grateful.
Log
From JavaScript console in Chrome:
blazor.webassembly.js:1 blazor Loaded 7.22 MB resourcesThis application was built with linking (tree shaking) disabled. Published applications will be significantly smaller.
blazor.webassembly.js:1 System.PlatformNotSupportedException: The default RestClientProvider is not supported on this platform. ---> System.PlatformNotSupportedException: Property AutomaticDecompression is not supported.
f.printErr @ blazor.webassembly.js:1
blazor.webassembly.js:1 at System.Net.Http.HttpClientHandler.set_AutomaticDecompression (System.Net.DecompressionMethods value) <0x2ab9320 + 0x0000c> in <filename unknown>:0
f.printErr @ blazor.webassembly.js:1
blazor.webassembly.js:1 at Discord.Net.Rest.DefaultRestClient..ctor (System.String baseUrl, System.Boolean useProxy) <0x2a9fd28 + 0x00024> in <filename unknown>:0
f.printErr @ blazor.webassembly.js:1
blazor.webassembly.js:1 at Discord.Net.Rest.DefaultRestClientProvider+<>c__DisplayClass1_0.<Create>b__0 (System.String url) <0x2a7f640 + 0x0000c> in <filename unknown>:0
f.printErr @ blazor.webassembly.js:1
blazor.webassembly.js:1 --- End of inner exception stack trace ---
f.printErr @ blazor.webassembly.js:1
blazor.webassembly.js:1 at Discord.Net.Rest.DefaultRestClientProvider+<>c__DisplayClass1_0.<Create>b__0 (System.String url) <0x2a7f640 + 0x00030> in <filename unknown>:0
f.printErr @ blazor.webassembly.js:1
blazor.webassembly.js:1 at Discord.API.DiscordRestApiClient.SetBaseUrl (System.String baseUrl) <0x2a7f1d8 + 0x00030> in <filename unknown>:0
f.printErr @ blazor.webassembly.js:1
blazor.webassembly.js:1 at Discord.API.DiscordRestApiClient..ctor (Discord.Net.Rest.RestClientProvider restClientProvider, System.String userAgent, Discord.RetryMode defaultRetryMode, Newtonsoft.Json.JsonSerializer serializer, Discord.RateLimitPrecision rateLimitPrecision, System.Boolean useSystemClock) <0x2a16270 + 0x000a2> in <filename unknown>:0
f.printErr @ blazor.webassembly.js:1
blazor.webassembly.js:1 at Discord.API.DiscordSocketApiClient..ctor (Discord.Net.Rest.RestClientProvider restClientProvider, Discord.Net.WebSockets.WebSocketProvider webSocketProvider, System.String userAgent, System.String url, Discord.RetryMode defaultRetryMode, Newtonsoft.Json.JsonSerializer serializer, Discord.RateLimitPrecision rateLimitPrecision, System.Boolean useSystemClock) <0x2a07280 + 0x00044> in <filename unknown>:0
f.printErr @ blazor.webassembly.js:1
blazor.webassembly.js:1 at Discord.WebSocket.DiscordSocketClient.CreateApiClient (Discord.WebSocket.DiscordSocketConfig config) <0x2a06680 + 0x00046> in <filename unknown>:0
f.printErr @ blazor.webassembly.js:1
blazor.webassembly.js:1 at Discord.WebSocket.DiscordSocketClient..ctor (Discord.WebSocket.DiscordSocketConfig config) <0x2a06180 + 0x0000a> in <filename unknown>:0
f.printErr @ blazor.webassembly.js:1
blazor.webassembly.js:1 at Discord.WebSocket.DiscordSocketClient..ctor () <0x29b75c8 + 0x0000a> in <filename unknown>:0
f.printErr @ blazor.webassembly.js:1
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Creating a chat widget by opening a Discord connection client-side would require you to embed the bot’s token in your WebAssembly payload. This would constitute sharing your bot token (aside from the other complications of opening a gateway connection for every visitor to your site) which is against ToS.
For your use-case, I recommend running a single Discord.Net bot as a .NET Core application, and exposing a separate WebSocket to relay messages to an external front-end (this would allow your front-end to print Discord messages without opening its own connection to Discord, and without exposing your credentials)
Thank You @foxbot for your recommendation. I’ll probably move my bot to server side and stop using D.Net in Blazor WASM. Maybe I will try to make bot automatically embed widget for user’s server in my web app. Closing issue.