Export (0) Print
Expand All
Expand Minimize

Conversion from '<type1>' to '<type2>' cannot occur in a constant expression used as an argument to an attribute

An expression used for an attribute argument evaluates to a data type different from that of the corresponding attribute parameter, and Visual Basic does not allow the required type conversion for attribute arguments.

An attribute provides metadata for the element it is applied to, and the compiler must be able to construct all the metadata at compile time. For this reason, every attribute must use values that are constant at compile time, and therefore every attribute argument must evaluate to a compile-time constant value.

Certain type conversions cannot produce values that are constant at compile time. For example, converting a String to a Double or a Date depends on the locale setting at run time. Other conversions, such as an array of a derived type to an array of Object, present a variety of problems that do not permit the compiler to allow them on attribute arguments.

Error ID: BC30934

To correct this error

  • Use an expression that evaluates to the same data type as the corresponding parameter, as defined by the attribute.

Community Additions

ADD
Show:
© 2015 Microsoft