ParameterInfo.ToString() is inconsistent with the .NET Framework behavior #110447
Labels
area-System.Reflection
needs-further-triage
Issue has been initially triaged, but needs deeper consideration or reconsideration
Description
I'm porting large amount of legacy code that relies on string comparison of various objects collected via reflection. (Code should run both on .NET Framework and .NET 8.0+)
Part of this code uses ParameterInfo.ToString() that has different behavior between the frameworks. (Changed in #52804, commit 0377084)
4.8 did not distinguish between null and
""
Name, while 6+ does. This in itself would not be a problem, as we are not comparing data between frameworks. However, .NET 8 sometimes returns null, sometimes""
for MethodInfo.ReturnParameter.Name, which, with the new behavior breaks tests.Yes, one could argue that ToString() output is not something to rely on, but
Reproduction Steps
See the attached repro project. Build and run both versions.
ParamInfo.zip
net48:
net8.0
Expected behavior
ParameterInfo should not distinguish between null and empty names, as both values mean that it does not have a name.
Actual behavior
Difference in behavior.
Regression?
Changed behavior from .NET Framework 4.8
Does not seem to be documented in https://learn.microsoft.com/en-us/dotnet/core/compatibility/6.0
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: