This documentation is archived and is not being maintained.

Expression of type '<typename1>' can never be of type '<typename2>'

A TypeOf...Is expression tests an object reference variable to a data type that it cannot hold.

In some cases the compiler can determine that a TypeOf...Is test can only fail, for example if there is no inheritance relationship between two classes.

The following code can generate this error.

Dim refVar as System.Windows.Forms.Form

If TypeOf refVar Is System.Array

End If

Because Form and Array are totally unrelated types, the compiler can determine that the TypeOf...Is expression returns False for any value of refVar.

Error ID: BC31430

To correct this error

  • Test the variable for a realistic data type, or remove the TypeOf...Is test altogether.