473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Reflection & InvokeMember problems!!

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
5 5011
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
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
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Svenn-Ivar Svendsen | last post by:
I'm implementing a windows application with generic support for scripting, and I'm using the microsoft script control (msscript). For vbscript/jscript I'm happy, but with python I got problems...
0
by: Linda Antonsson | last post by:
Hi, I am trying to put together a CSS-based layout consisting of a header, a sidebar and a main content area. Page: http://www.westeros.org/ASoWS/ CSS:...
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
0
by: Albert Greinoecker | last post by:
Hi, I have a problem with reflection in c#. I'm trying to create an object of a class of a different assembly using e.g. Type.GetType("ns1.ns2.ClassName"), and it does not work, because first I...
8
by: paccala | last post by:
Ciao Being google-ing since hours and still I'm not able to solve my problem... I have following hierarchy: class A { public void myMethod(); }
2
by: Shmuel Cohen | last post by:
I have a class holding some enumerated types, i.e., public class MyEnums { public enum DATA_ITEM {FIRST, SECOND, THIRD,FOURTH,FIFTH}; ... } And I have a class the contains data, for example:
1
by: Francesco Mancini | last post by:
Hi all I'm working with c# and I need to load (runtime) a COM ActiveX (written in VB6, I think...); and this is not a problem (with Reflection class)... the problem is that this ocx has a menu,...
5
by: papa.coen | last post by:
Consider the following method: TOTAL(string v, params Object c) Called with the following values : A, {B, {C, {D,E},F} or (as a 'structured' array layout) : A, B
4
by: Dov Tendler | last post by:
Hi All, I would like to get MethodInfo of current instantiated generic method call. Consider the following function call: C.f<int>(5); Where f is defined as follows: class C {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.