Description
Type of issue
Spec incorrect
Description
I wanted to provide some feedback regarding section 22.2.4 of the C# specification, which outlines the supported types for attribute parameters. While the documentation mentions "single-dimensional arrays of the above types" as valid attribute parameter types, it doesn't explicitly clarify that arrays of reference types like string are treated differently by the compiler in certain scenarios.
For example, while new int[] {1, 2} works fine as an attribute argument, new string[] {"foo", "bar"} produces the error "An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type." This behavior stems from how the compiler handles arrays of reference types versus primitive types in constant expressions.
It would be helpful if the documentation explicitly stated that single-dimensional arrays of reference types (such as string, object, and System.Type) are subject to limitations when used as attribute arguments, even if they are technically valid attribute parameter types.
Thank you for considering this feedback to improve clarity in the C# documentation!
UPDATE: Apologies for missing an important fact. This reproduces when using the Online data attribute on xUnit. It does takes the parameters as an object[].
Page URL
Content source URL
https://github.com/dotnet/csharpstandard/blob/draft-v8/standard/attributes.md