An attribute argument must be a constant expression, …- Create an attribute of type array

This supplements the information Simon already gave.

I found some documentation here: Attribute parameter types:

The types of positional and named parameters for an attribute class are limited to the attribute parameter types, which are:

  • One of the following types: bool, byte, char, double, float, int, long, sbyte, short, string, uint, ulong, ushort.
  • The type object.
  • The type System.Type.
  • An enum type, provided it has public accessibility and the types in which it is nested (if any) also have public accessibility (Attribute specification).
  • Single-dimensional arrays of the above types. (emphasis added by me)

A constructor argument or public field which does not have one of these types, cannot be used as a positional or named parameter in an attribute specification.

The last bullet point explains your syntax error. You’ve defined a one-dimensional array, but it should only be of primitive types, string, etc. as listed in the previous bullet points.

Leave a Comment