tmenier / Flurl

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

.net 8 blazor wasm PlatformNotSupportedException #823

Open codegurney opened 6 months ago

codegurney commented 6 months 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 6 months ago

What version of Flurl.Http?

eric-gurney-omac commented 6 months ago

4.0.2

eric-gurney-omac commented 6 months 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 6 months 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 6 months 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 6 months 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 6 months ago

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