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.
See also
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for