A breaking change in .NET argument exception message formatting
A quick reference post about an interesting change in the way .NET formats argument exception messages. This tripped me up when debugging a test that was failing on .NET Core / 6.0 whereas it had been passing forever and still passes on .NET Framework / 4.7. The test was expecting a specific error message. Because .NET Core apparently has changed the format string used for argument exception messages, that expectation was broken.
Technically a breaking change, but then again expecting a specific error message is usually not the best idea.
Anyway, here's how .NET 4.7 formats the exception:
And here's how .NET 6.0 does:
The fix for the test of course is to test for the presence of the message that was passed in when creating the exception as a substring of the exception's Message property, instead of expecting the whole formatted message.