Code inspection: Possibly misleading 'DefaultValueAttribute' usage to define optional parameter value
This inspection reports use of DefaultValueAttribute to define the default value of an optional parameter. DefaultValueAttribute is not the correct attribute for optional parameter metadata.
Example
using System.Runtime.InteropServices;
using System.ComponentModel;
void Log([Optional, DefaultValue(1)] int level)
{
}
This looks like an optional parameter declaration, but DefaultValueAttribute is meant for other scenarios and can be misleading here.
How to fix it
There is no dedicated quick-fix for this inspection. Use DefaultParameterValueAttribute for optional parameters.
using System.Runtime.InteropServices;
void Log([Optional, DefaultParameterValue(1)] int level)
{
}
01 April 2026