I reproduced your issue in my side, I have .Net 8 MVC App, .Net 8 Console App and .Net Framework 4.8 App. .Net 8 MVC app and .Net 8 Console app have the same test result. The test results are the same even if I set CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
.
However, when I copy the value from MVC project and paste, I will get 12/10/2024
just like what you shared, but not what I can see 2024/10/12
. While the value copyed from .Net Framework app is the same as what we can see, it's 12/10/2024
. Then I searched online which said this is due to Unicode bidirectional marks such as Right-to-Left Marks (RLM) (U+200F) are automatically added to the formatted output which suggest adding string cleanResult = Regex.Replace(result, @"[\u200F\u200E]", "");
to remove the marks. I test in my side which worked. Here's the Microsoft Document for introducing the differences about globalization APIs. So that I agree with what Matthew Watson shared which using <RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
, it will ask applications can enable NLS mode instead of the default ICU in .Net 8. The document also shared another way which set configurations below in runtimeconfig.json
.
{
"runtimeOptions": {
"configProperties": {
"System.Globalization.UseNls": true
}
}
}
Before .NET 5, the .NET globalization APIs used different underlying
libraries on different platforms. On Unix, the APIs used International
Components for Unicode (ICU), and on Windows, they used National
Language Support (NLS). This resulted in some behavioral differences
in a handful of globalization APIs when running applications on
different platforms.
\u200f/
as a delimiter where\u200f
is a special 'Right-to-left mark' symbol – Epicalyx