Resl1021 Multi Argument Ierror Constructor Warning
title: RESL1021 — Multi-Argument IError Constructor [Warning]
Warns when an IError or IReason implementation has a public constructor with 2+ required parameters. Multi-parameter public constructors prevent [CallerMemberName] capture at the factory call site and make the API ambiguous.
Allowed: (), (string), (string, Exception), [Obsolete]-marked ctors, non-public ctors, and ctors where all extra params are optional (e.g., [CallerMemberName] string? = null).
// ⚠️ RESL1021: 'MyError' has a public constructor with 2+ required parameters
public class MyError : IError
{
public MyError(string entity, string field) { ... } // ← RESL1021
public string Message { get; }
}
// ✅ use a static factory instead:
public class MyError : IError
{
public MyError(string message) { ... } // single-string ctor — allowed
public static MyError For(string entity, string field,
[CallerMemberName] string? callerMember = null, ...) => ...; // ← CallerMember captured here
}