Code inspection: The CallerLineNumberAttribute will have no effect because it applies to a member that is used in contexts that do not allow optional arguments
This inspection reports [CallerLineNumber] applied where caller info cannot be consumed. One common case is putting the attribute on the implementation part of a partial method instead of on the defining declaration that carries the optional parameter. In that position, the attribute has no effect.
Example
using System.Runtime.CompilerServices;
partial class C
{
public partial void M(int line = 0);
}
partial class C
{
public partial void M([CallerLineNumber] int line)
{
}
}
using System.Runtime.CompilerServices;
partial class C
{
public partial void M([CallerLineNumber] int line = 0);
}
partial class C
{
public partial void M(int line)
{
}
}
Quick-fix
When another partial declaration exists, the quick-fix can move the attribute onto the declaration part where it is effective.
21 April 2026