Skip to main content

How to Resolve Error "CS0674: Do not use 'System.ParamArrayAttribute'. Use the 'params' keyword instead." in C#

The Compiler Error CS0674 is a syntax restriction error. The message reads: "Do not use 'System.ParamArrayAttribute' (or 'System.Runtime.CompilerServices.ParamCollectionAttribute'). Use the 'params' keyword instead."

In C#, the params keyword is "syntactic sugar." When you use params, the compiler automatically generates the underlying metadata attribute ([ParamArray] or [ParamCollection]) in the compiled Intermediate Language (IL) code. This attribute tells the Common Language Runtime (CLR) that the method accepts a variable number of arguments.

To prevent conflicts and ensure consistent IL generation, C# forbids you from manually applying these attributes. You must use the language keyword.

Understanding params vs. Attributes

  • The C# Way: You write void Method(params int[] args).
  • The IL Way: The compiler translates this to void Method([ParamArray] int[] args).

If you try to skip the C# keyword and write the IL definition directly in C#, the compiler stops you. It reserves the right to manage these specific attributes itself.

Scenario 1: Using ParamArrayAttribute Manually

This often happens when developers are porting code from other .NET languages, working with Reflection APIs and getting confused about definition syntax, or trying to be "explicit" about metadata.

Example of error: attempting to apply [ParamArray] to an array parameter.

using System;

public class Calculator
{
// ⛔️ Error CS0674: Do not use 'System.ParamArrayAttribute'.
// Use the 'params' keyword instead.
public void Add([ParamArray] int[] numbers)
{
foreach (var n in numbers)
{
Console.WriteLine(n);
}
}
}

Scenario 2: Using ParamCollectionAttribute (C# 13+)

In modern C# versions (C# 13 / .NET 9), the params keyword was expanded to support collections other than arrays (like List<T> or Span<T>). Under the hood, this uses System.Runtime.CompilerServices.ParamCollectionAttribute.

The same rule applies: do not use the attribute manually.

Example of error:

using System.Runtime.CompilerServices;
using System.Collections.Generic;

public class Printer
{
// ⛔️ Error CS0674: Do not use 'ParamCollectionAttribute'.
public void PrintNames([ParamCollection] List<string> names)
{
}
}

Solution: Use the params Keyword

The solution is always to replace the attribute with the standard C# keyword.

Solution: replace the attribute [ParamArray] (or [ParamCollection]) with the keyword params before the type.

using System;
using System.Collections.Generic;

public class Calculator
{
// ✅ Correct: Using standard syntax for arrays
public void Add(params int[] numbers)
{
// ...
}

// ✅ Correct: Using standard syntax for collections (C# 13+)
public void PrintNames(params List<string> names)
{
// ...
}
}
note

Why does C# forbid the attribute? The params keyword implies more than just the attribute. It enforces rules like "params must be the last parameter" and ensures the parameter type is valid (array or collection). If you used the attribute manually, the compiler might fail to enforce these language-specific rules correctly.

Conclusion

CS0674 ensures you use the language features correctly.

  1. Identify the Attribute: Are you using [ParamArray] or [ParamCollection]?
  2. Remove it: Delete the attribute declaration.
  3. Add Keyword: Add params before the parameter type.