You cannot cast an object to any class; you can only cast it as being of a class that is derived from its stated class. In the CAST expression in this statement, the stated class of the object reference on the left is not a base class of the class that is named as the right argument. Review the expression to make sure that you have specified the object that you intended (possibly you need to use parentheses around the object reference) and the target class.