I upgrade a Web App from .NET 6 to .NET 8 and ran into the same issue - precisely the same error message.
I updated Nuget packages related to Microsoft.AspNetCore (components, razor runtime, etc.) to the latest version 8 (8.0.11 at this time), and as suggest by @Darkseal I also added the System.Security.Cryptography.Pkcs version 8.0.1.
This resolved the issue.