Compiler Error CS0182

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

Certain restrictions apply to what kinds of arguments may be used with attributes. Note that in addition to the restrictions specified in the error message, the following types are NOT allowed as attribute arguments:

For more information, see Global Attributes (C# Programming Guide).

Example

The following sample generates CS0182:

// CS0182.cs
public class MyClass
{
    static string s = "Test";

    [System.Diagnostics.ConditionalAttribute(s)]   // CS0182
    // Try replacing variable s with constant "Test".
    // [System.Diagnostics.ConditionalAttribute("Test")]
    void NonConstantArgumentToConditional()
    {
    }

    public static void Main()
    {
    }
}

See Also

Reference

Arrays (C# Programming Guide)

Constants (C# Programming Guide)

typeof (C# Reference)