In my case, the same issue was due to using System.Text.Json v9.0.0 together with .NET 6.
I managed to solve this by downgrading System.Text.Json to v8.0.5, which is non-vulnerable, non-deprecated as of June 2025.
If you have the possibility to do so, though, it would be better to upgrade the target framework to .NET 8 or later and that would solve the issue as well.