0 out of 5 rated this helpful - Rate this topic

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).

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()
    {
    }
}
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ