tmenier / Flurl

Fluent URL builder and testable HTTP client for .NET
https://flurl.dev
MIT License
4.04k stars 378 forks source link

.net 8 blazor wasm PlatformNotSupportedException #823

Open codegurney opened 3 weeks ago

codegurney commented 3 weeks ago

Using the code from the docs on a Blazor WASM application: `services.AddSingleton(sp => new FlurlClientCache() .Add("MyCli", "https://some-api.com"));

public MyService(IFlurlClientCache clients) { _flurlCli = clients.Get("MyCli");`

causes a PlatformNotSupportedException. Looking at the stack trace, it looks like it is related to UseCookies.

tmenier commented 2 weeks ago

What version of Flurl.Http?

eric-gurney-omac commented 1 week ago

4.0.2

eric-gurney-omac commented 1 week ago

Looking into this a little more, it is a handled exception, but Rider is still breaking when this exception is thrown. Would it be possible to check for WASM before setting the UseCookies property on HttpClientHandler?

tmenier commented 1 week ago

That try/catch is meant to be sort of a future-proof catch-all so Flurl doesn't need to sniff for specific platforms. I'll make a note to look at it, there's some sniffing going on in other areas so this isn't a hard rule. Can you exclude PlatformNotSupportedException from exceptions that Rider breaks on? You can in VS but I'm less familiar with Rider.

tmenier commented 1 week ago

And along the lines of future-proofing, if some future version of WASM adds support for UseCookies, this could cause problems. So it's kind of doubtful I'll make a change here, but I will still take a look at it.

codegurney commented 1 week ago

Probably. For now, at least in development, I have forked the repo and added... `#if NETCOREAPP if (!OperatingSystem.IsBrowser())

endif

before the call to handler.UseCookies = false;` in FlurlClientFactory.cs

codegurney commented 1 week ago

maybe add configuration option to toggle whether or not to use cookies?