Reflection & InvokeMember problems!!

  • Thread starter Thread starter Karthik Vazhkudai
  • Start date Start date
K

Karthik Vazhkudai

I have a class defined in VC.NET with the following code:
namespace AlertSystem
{
public __value class CFilterRegion
{
public:
System::Int16 X1;
System::Int16 Y1;
System::Int16 X2;
System::Int16 Y2;
System::Int16 X3;
System::Int16 Y3;
System::Int16 X4;
System::Int16 Y4;
}

I then import this alertsystem namespace in a VB.NET project and then
try to set the values of an object instantiated from the above
CFilterRegion class. The code is as below:

Dim obj2 As New CFilterRegion
Dim t As Type = GetType(CFilterRegion)
Try
t.InvokeMember("X1", BindingFlags.SetField, Nothing, obj2,
New Object() {666})
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try

But an error is thrown stating that "Object type cannot be converted
to target type".

The weird thing is that when I define my CFIlterRegion class within
the same VB project (instead of importing from a VC.NET project) the
InvokeMember works fine for both SetField and GetField.

I would appreciate if anyone can throw some light on this issue that I
am having.

Thanks,
Karthik
 
Sorry you have posted this in the wrong newgroup. Please refer to visual c
NG


Regards OHM
 
Karthik Vazhkudai said:
[...]> System::Int16 X1;
[...]
t.InvokeMember("X1", BindingFlags.SetField, Nothing,
obj2,
New Object() {666})


Without having read it thoroughly:
... New object(){666S})

Watch the "S" (short) at the end.
 
Sorry, just ignore my post , I didnt read all the way down before replying.

Appologies. - OHM
 
Hello:

I tried adding the 'S' at the end of 666. Now it doesnt throw an error
but it doesnt set the value for the "X5" field. Also the "SetField"
doesnt work either (it returns a 0). What am I missing, or this is a
quirk in using imported classes from a different assembly?

Thanks.

Armin Zingler said:
Karthik Vazhkudai said:
[...]> System::Int16 X1;
[...]
t.InvokeMember("X1", BindingFlags.SetField, Nothing,
obj2,
New Object() {666})


Without having read it thoroughly:
... New object(){666S})

Watch the "S" (short) at the end.
 
Karthik Vazhkudai said:
I tried adding the 'S' at the end of 666. Now it doesnt throw an
error but it doesnt set the value for the "X5" field.

Which X5 field? I can find X1 to X4.
Also the
"SetField" doesnt work either (it returns a 0). What am I missing, or
this is a quirk in using imported classes from a different
assembly?

Hmm.... Does *Set*Field have to return anything?
 
Back
Top