question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor Web Assembly - error while creating DiscordSocketClient.

See original GitHub issue

Issue

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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
foxbotcommented, Jul 7, 2020

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)

0reactions
RevanJJPcommented, Jul 8, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blazor and .NET6 creates an error: EntrypointInvoker in ...
I have my simple project with Blazor. I updated the project from .NET5 to .NET6. I deploy to the production environment using Web...
Read more >
Blazor Webassembly error when adding a ASP.NET Core ...
I created two fresh new projects a Blazor Web Assembly without checking the option of ASP.NET Core hosted because I did not want...
Read more >
Handle errors in ASP.NET Core Blazor apps
This article describes how Blazor manages unhandled exceptions and how to develop apps that detect and handle errors.
Read more >
blazor template can't build on cli
Try to update Blazor templates and create Blazor Server App or Blazor WebAssembly App. Install latest Templates. Copy. dotnet new --install ...
Read more >
Blazor WASM app won't load after publish. Works fine on ...
This is the only error I get when loading the site: "Uncaught (in promise) Error: Error loading ICU asset. at blazor.webassembly.js:1:37837".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found