Expression has the type '<typename>' which is a restricted type and cannot be used to access members inherited from 'Object' or 'ValueType'

An expression evaluates to a type that cannot be boxed by the common language runtime (CLR) but accesses a member that requires boxing.

Boxing refers to the processing necessary to convert a type to Object or, on occasion, to ValueType. The common language runtime cannot box certain structure types, for example ArgIterator, RuntimeArgumentHandle, and TypedReference.

This expression attempts to use the restricted type to call a method inherited from Object or ValueType, such as GetHashCode or ToString. To access this method, Visual Basic has attempted an implicit boxing conversion that causes this error.

Error ID: BC31393

To correct this error

  1. Locate the expression that evaluates to the cited type.

  2. Locate the part of your statement that attempts to call the method inherited from Object or ValueType.

  3. Rewrite the statement to avoid the method call.

See Also

Implicit and Explicit Conversions