FieldInfo.SetValue failing under VB.Net 2003

L

Laurie

Hi,

I need to be able to manipulate field values within a structure using
FieldInfo.GetValue and FieldInfo.SetValue, in VB.Nt 2003. The GetValue
is working fine and makes it really easy for me to maintain my code.
Unfortunately, SetValue doesn't return any errors but doesn't actually
set the value.

I have read through various newsgroup postings, and think the problem
might have something to do with "boxing", and passing of structures by
reference instead of by value. As such, I think I might be modifying a
copy of the structure, not the original structure itself. Even more
strange is that during my attempts to make it work, I found I could
issue a SetValue command within the Command Window in the VB.Net IDE
(and it would work), but the same code placed in the program did not
work. I suspect this is also to do with copies of the structure
instead of the original.

Anyway, the code below doesn't return any errors, but also doesn't set
the value! Please can somebody help me? I don't want to have to
redesign the code, and getting this working would make it really
efficient and easy to maintain

Thanks in advance

Laurie


Module module1

Structure ConfigVariables
Dim FirstVar As String
Dim SecondVar As String
Dim ThirdVar As String
End Structure


Sub Main()

Dim fld As System.Reflection.FieldInfo
Dim myType As Type = GetType(ConfigVariables)
Dim myFields As System.Reflection.FieldInfo() = myType.GetFields()
For Each fld In myFields
fld.SetValue(CV, "Test Value")
Next fld

End Sub
 
L

Laurie

Have tried various other ways to resolve this, but still to no avail.
Has anyone got any ideas? Thanks, Laurie
 

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