E
Ewald Hofman
I have a very strange typing problem:
There is the following class
Public Class MyBaseClass
Implents MyInterface
Public Property MyProperty As MyClass implements MyInterface.MyProperty
...
End Class
I want to execute a method that uses the MyProperty from the MyBaseClass. So I made some tries to achieve this:
Try 1
public sub myMethod(argument as MyInterface)
dim MyObject as MyClass = argument.MyProperty
end sub
When I call the method I get the following exception: MissingMethodException (although the watch and immediate window gave me access to the property)
Try 2
When I define the method as follows (option strict is off):
public sub myMethod(argument as object)
dim MyObject as MyClass = CType(argument.MyProperty, MyClass)
end sub
I don't get the MissingMethodException anymore, but now I get the InvalidCastException (although I can perform the CType correctly in the watch and immediate window)
Try 3
When I define the method as follows (option strict is off):
public sub myMethod(argument as object)
dim MyObject as MyClass
If TypeOf argument.MyProperty Is MyClass Then
MyObject = CType(argument.MyProperty, MyClass)
End If
end sub
Now the CType is never performed and now there is the best of all: when I set the a breakpoint on the TypeOf line, then the watch window tells me the expression is true, but in the code window the expression is false, because it doesn't perform the CType.
Does anyone know what to do ????
Thanks in advance
Ewald Hofman
There is the following class
Public Class MyBaseClass
Implents MyInterface
Public Property MyProperty As MyClass implements MyInterface.MyProperty
...
End Class
I want to execute a method that uses the MyProperty from the MyBaseClass. So I made some tries to achieve this:
Try 1
public sub myMethod(argument as MyInterface)
dim MyObject as MyClass = argument.MyProperty
end sub
When I call the method I get the following exception: MissingMethodException (although the watch and immediate window gave me access to the property)
Try 2
When I define the method as follows (option strict is off):
public sub myMethod(argument as object)
dim MyObject as MyClass = CType(argument.MyProperty, MyClass)
end sub
I don't get the MissingMethodException anymore, but now I get the InvalidCastException (although I can perform the CType correctly in the watch and immediate window)
Try 3
When I define the method as follows (option strict is off):
public sub myMethod(argument as object)
dim MyObject as MyClass
If TypeOf argument.MyProperty Is MyClass Then
MyObject = CType(argument.MyProperty, MyClass)
End If
end sub
Now the CType is never performed and now there is the best of all: when I set the a breakpoint on the TypeOf line, then the watch window tells me the expression is true, but in the code window the expression is false, because it doesn't perform the CType.
Does anyone know what to do ????
Thanks in advance
Ewald Hofman