This is to backport the fix for: https://github.com/dotnet/runtime/issues/34478 to 3.1. This will also required this PR to be backported to avoid a regression on Alpine: https://github.com/dotnet/runtime/pull/41532.