'Xamarin app crashes with The type initializer for 'System.Text.Json.JsonSerializer' threw an exception after SignalR install

After adding SignalR client to my Xamarin Forms app, it started crashing shortly after launching.

The error I get is:

System.InvalidOperationException
Message=Error loading discovery document: Error connecting to https://myapp.auth0.com/.well-known/jwks.json. The type initializer for 'System.Text.Json.JsonSerializer' threw an exception..

This is happening when I try to test the app on my iPhone. On Android, everything seems to be working fine.

Has anyone received this error? Are there known issues with SignalR on Xamarin Forms 5? Any suggestions for resolving the issue?

My app is on Xamarin Forms 5.0.0.2401 and SignalR client I installed is Microsoft.AspNetCore.SignalR.Client 6.0.5.

UPDATE:

The error seems to be thrown by Auth0 but it definitely happens after installing SignalR becuase prior to installing it, everything works perfectly fine.

Interestingly, SignalR seems to upgrade system.text.encodings.web to the latest stable version which is 6.0.0 and the suggestion in the link below as well as Auth0 forums suggest upgrading to this version. So, in my case, this version is just not preventing the error. Here's the packages SignlR depends on -- see below. So, at this point, I'm still stuck with the error.

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source