2

I have tried adding ServiceStack-references to a client-side Blazor project, but I run into problems after adding ServiceStack.HttpClient via NuGet.

Currently, VS2019 will tell me that:

Cannot find declaration of exported type 'System.Threading'

and when ask/look around, they say that:

Blazor is built using mono-wasm as the base .NET framework implementation, and in this case I believe it's a missing method in mono-wasm that's the issue.

and

at present Mono WASM has no support for threading; check the repo https://github.com/lrz/mono-wasm-mono for more info

Am I getting it correctly:

  • ServiceStack requires System.Threading
  • WebAssembly and thus Blazor does not support references to System.Threading
  • Meaning that ServiceStack cannot be used in a Blazor app

2 Answers 2

3

ServiceStack's Blazor WASM Template is being maintained by Sebastian Faltoni at https://github.com/nukedbit/blazor-wasm-servicestack

Which can be installed with the x dotnet tool:

$ dotnet tool install -g x

and created with:

$ x new nukedbit/blazor-wasm-servicestack ProjectName

Or for an installation-free alternative use ServiceStack's online project template builder: https://servicestack.net/start#community

It includes integration with a Blazor Service Client which can be created at:

var client =  BlazorClient.Create("https://localhost:5001")

It currently returns a pre-configured JsonHttpClient that removes all HttpClient features that Blazor WASM doesn't support. Over time we'll include more features as they're supported in Blazor.

@Issac is incorrect about ServiceStack using Web Sockets, ServiceStack doesn't use Web Sockets in any of its libraries and BlazorClient is a Service Client using .NET's HttpClient which Blazor WASM does support.

3
  • Thanks Mythz. So, you are going to look at Blazor support when its officially released, if I read your answer correcty?
    – Ted
    May 31, 2019 at 19:14
  • 2
    @Ted Right, will be looking into a JSON Service Client for Blazor after it’s officially released.
    – mythz
    May 31, 2019 at 20:20
  • Mythz has updated the answer on sept 11 2021, so now there is some support for Blazor client it seems.
    – Ted
    Jan 23, 2022 at 16:10
1

@Ted,

Blazor does not run in a multi-thread environment. Blazor (mono-wasm) runs in the same sandbox of JavaScript, in the same UI thread. No multi-threading, no concurrent or parallel programming. As I've said before, I've never heard of ServiceStack, but I guess that ServiceStack.HttpClient cannot be used in Blazor client side, as "Blazor HttpClient" is based on HttpMessageHandler, and it is adapted to work as an Ajax agent; that is, HttpClient communicate with the Back End via the JavaScript Fetch Web API, whereas ServiceStack, I believe, perform the traditional http client calls, employing Web Sockets, which is not supported in Blazor (mono-wasm). In Asp.Net Core 5.0 it is expected that Blazor client side would support Web Sockets, after mono would be replaced.

No, the ServiceStack cannot be used in a Blazor app

Hope this helps...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.