InvokeMember Exception

  • Thread starter Thread starter Miguel
  • Start date Start date
M

Miguel

I ran into a very strange problem today. I'm trying to invoke a
property from a very basic class. I always get a NotSupportedException.
Anyone?

Public Class A
Public Readonly Property val as String()
Get
return "Testing"
End Get
End Property
End Class

....
Dim t as Type = GetType(A)
Dim k as new A
Dim ret as Object =
t.InvokeMember("val",BindingFlags.GetProperty,Nothing,k,Nothing)
 
As it says, InvokeMember is not supported. Use
Type.GetMember(...).Invoke(...) instead.

Cheers
Daniel
 
This should work for you:

Dim t as Type = GetType(A)
Dim pi As PropertyInfo = t.GetProperty("val")
Dim ret As Object = pi.GetValue(k, Nothing)
 
....or looking again at your original code, maybe GetProperty(...).GetValue
will do you better... use intellisense ;)

Cheers
Daniel
 
Back
Top