This solution works for me: Add <CETCompat>false</CETCompat> to project file if you saw this error when migrating apps to Net Core 9 framework. There is a break change in Net Core 9:
https://github.com/dotnet/runtime/issues/108589
https://github.com/dotnet/docs/issues/42600