By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,890 Members | 1,115 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,890 IT Pros & Developers. It's quick & easy.

Reflection & InvokeMember problems!!

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Sorry you have posted this in the wrong newgroup. Please refer to visual c
NG
Regards OHM

"Karthik Vazhkudai" <ka*******@yahoo.com> wrote in message
news:dd**************************@posting.google.c om...
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

Nov 20 '05 #2

P: n/a
Sorry, just ignore my post , I didnt read all the way down before replying.

Appologies. - OHM
"One Handed Man [ OHM ]" <te***************************@BTOpenworld.com>
wrote in message news:ea**************@TK2MSFTNGP09.phx.gbl...
Sorry you have posted this in the wrong newgroup. Please refer to visual c
NG
Regards OHM

"Karthik Vazhkudai" <ka*******@yahoo.com> wrote in message
news:dd**************************@posting.google.c om...
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


Nov 20 '05 #3

P: n/a
"Karthik Vazhkudai" <ka*******@yahoo.com> schrieb
[...]> 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.
--
Armin

Nov 20 '05 #4

P: n/a
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" <az*******@freenet.de> wrote in message news:<eU*************@TK2MSFTNGP11.phx.gbl>...
"Karthik Vazhkudai" <ka*******@yahoo.com> schrieb
[...]> 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.

Nov 20 '05 #5

P: n/a
"Karthik Vazhkudai" <ka*******@yahoo.com> schrieb

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?
--
Armin

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.