InvokeMember Exception

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)
 
D

Daniel Moth

As it says, InvokeMember is not supported. Use
Type.GetMember(...).Invoke(...) instead.

Cheers
Daniel
 
S

Sergey Bogdanov

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)
 
D

Daniel Moth

....or looking again at your original code, maybe GetProperty(...).GetValue
will do you better... use intellisense ;)

Cheers
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top