Parameter and argument mismatch

The compiler generates the following errors when there's no argument supplied for a formal parameter, or the argument isn't valid for that parameter:

  • CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
  • CS0591: Invalid value for argument to attribute
  • CS0599: Invalid value for named attribute argument 'argument'
  • CS0617: Not a valid named attribute argument. Named attribute arguments must be fields which are not readonly, static, or const, or read-write properties which are public and not static.
  • CS0633: The argument to the attribute must be a valid identifier
  • CS0643: Duplicate named attribute argument
  • CS0655: Not a valid named attribute argument because it is not a valid attribute parameter type
  • CS0839: Argument missing.
  • CS1016: Named attribute argument expected
  • CS1739: The best overload for does not have a parameter named
  • CS1740: Named argument cannot be specified multiple times
  • CS1742: An array access may not have a named argument specifier
  • CS1744: Named argument specifies a parameter for which a positional argument has already been given
  • CS1746: The delegate does not have a parameter named 'name'
  • CS7036: There is no argument given that corresponds to the required parameter
  • CS7067: Attribute constructor parameter is optional, but no default parameter value was specified.
  • CS8324: Named argument specifications must appear after all fixed arguments have been specified in a dynamic invocation.
  • CS8905: A function pointer cannot be called with named arguments.
  • CS8943: null is not a valid parameter name. To get access to the receiver of an instance method, use the empty string as the parameter name.
  • CS8944: Method is not an instance method, the receiver cannot be an interpolated string handler argument.
  • CS8945: Not a valid parameter name.
  • CS8948: InterpolatedStringHandlerArgumentAttribute arguments cannot refer to the parameter the attribute is used on.
  • CS8949: The InterpolatedStringHandlerArgumentAttribute applied to parameter is malformed and cannot be interpreted. Construct an instance of it manually.
  • CS8950: Parameter is an argument to the interpolated string handler conversion on parameter, but the corresponding argument is specified after the interpolated string expression. Reorder the arguments.
  • CS8951: Parameter is not explicitly provided, but is used as an argument to the interpolated string handler conversion on parameter.
  • CS8964: The CallerArgumentExpressionAttribute may only be applied to parameters with default values
  • CS8965: The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential.
  • CS8966: The CallerArgumentExpressionAttribute will have no effect because it applies to a member that is used in contexts that do not allow optional arguments

Missing argument

The following general errors are issued when the compiler can't match arguments to all member parameters:

  • CS0839: Argument missing.
  • CS7036: There is no argument given that corresponds to the required parameter

These errors are general: The compiler can't match the arguments given in a method call to the required parameters of the method. Check the following causes:

  • Make sure you included all necessary arguments.
  • Make sure the arguments are in the correct order.
  • Make sure all arguments are the correct type.
  • Make sure overload resolution rules chose the method you expected.

You might also see CS7036 if you wrote overloaded local functions. Local functions can't be overloaded. The compiler only recognizes the first local function with that name. Check if you meant to call a different local function.

These errors often appear with other diagnostics that can help diagnose the correct cause.

Arguments for attributes

The compiler issues these errors when an argument to an attribute constructor is incorrect:

  • CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
  • CS0591: Invalid value for argument to attribute
  • CS0599: Invalid value for named attribute argument 'argument'
  • CS0617: Not a valid named attribute argument. Named attribute arguments must be fields which are not readonly, static, or const, or read-write properties which are public and not static.
  • CS0633: The argument to the attribute must be a valid identifier
  • CS0643: Duplicate named attribute argument
  • CS0655: not a valid named attribute argument because it is not a valid attribute parameter type

If you use the System.AttributeUsageAttribute on your attribute definition, make sure the allowed values aren't mutually exclusive. Check that the type and order of arguments to the attribute are correct. Make sure the text of string arguments is valid. For many attributes, the argument must be a valid C# identifier. Arguments to attribute constructors must be compile-time constants. Therefore, they're limited to types that support literal constants. In addition, the following types that allow literal constants are disallowed as attribute parameters:

You can't specify repeated named arguments with the same parameter name. You can only set accessible properties when you initialize an attribute. You can't set private properties.

Named and optional parameters and arguments

The compiler issues the following errors for incorrect use of named and optional arguments:

  • CS1016: Named attribute argument expected
  • CS1739: The best overload for does not have a parameter named
  • CS1740: Named argument cannot be specified multiple times
  • CS1742: An array access may not have a named argument specifier
  • CS1744: Named argument specifies a parameter for which a positional argument has already been given
  • CS1746: The delegate does not have a parameter named 'name'
  • CS7067: Attribute constructor parameter is optional, but no default parameter value was specified.
  • CS8324: Named argument specifications must appear after all fixed arguments have been specified in a dynamic invocation.
  • CS8905: A function pointer cannot be called with named arguments.

Check for the following causes of these errors:

  • The parameter name of the named argument is incorrect.
  • The chosen overload doesn't have a parameter matching the named argument.
  • A parameter name is repeated on more than one argument.
  • A positional (unnamed) argument appears after named arguments.
  • Named arguments aren't allowed for array index parameters.

Interpolated string handler

The compiler issues the following errors when you specified an interpolated string handler incorrectly.

  • CS8943: null is not a valid parameter name. To get access to the receiver of an instance method, use the empty string as the parameter name.
  • CS8944: Not an instance method, the receiver cannot be an interpolated string handler argument.
  • CS8945: Not a valid parameter name.
  • CS8948: InterpolatedStringHandlerArgumentAttribute arguments cannot refer to the parameter the attribute is used on.
  • CS8949: The InterpolatedStringHandlerArgumentAttribute applied to parameter is malformed and cannot be interpreted. Construct an instance manually.
  • CS8950: Parameter is an argument to the interpolated string handler conversion on parameter, but the corresponding argument is specified after the interpolated string expression.
  • CS8951: Parameter is not explicitly provided, but is used as an argument to the interpolated string handler conversion on parameter.

An interpolated string handler is a pattern-based construct. It's important to get the pattern correct. Consult the feature spec, or follow the tutorial on building an interpolated string handler.

Caller debugging information

The compiler issues the following error on an incorrect use of the System.Runtime.CompilerServices.CallerArgumentExpressionAttribute:

  • CS8964: The CallerArgumentExpressionAttribute may only be applied to parameters with default values

In addition, the compiler issues the following warnings on an incorrect use of the CallerArgumentExpressionAttribute:

  • CS8965: The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential.
  • CS8966: The CallerArgumentExpressionAttribute will have no effect because it applies to a member that is used in contexts that do not allow optional arguments

Any parameter annotated with the CallerArgumentExpression attribute must have a default value.