473,320 Members | 1,861 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,320 software developers and data experts.

Reflection on instance returned from W/Service

Hi y'all ...

I've just come across a rather weird problem.

i'm using the following code to get the names of the public properties of an
object:

public static string[] GetPropertyNames(object instance){
Type objType = instance.GetType();
PropertyInfo[] props = objType.GetProperties();
string[] strPropNames = new string[props.Length];
for(int i=0; i<props.Length; i++)
strPropNames[i] = props[i].Name;
return strPropNames;
}

... that worked fine on framework class instances, and it also worked on my
own classes, even after I'd loaded an assembly dynamically from the file
system.

HOWEVER, now I'm using it to query an instance of a class returned from a
web service. I know that the class has several public properties [duh! I
wrote it !], but the code above doesn't work. It returns a zero-length
string array. A similar function that returns the method names, returns the
classic "object" methods, which is again not correct [quering for the method
names should also return the "get_<public property name>" methods for each
public property ... ]

Does anyone have a clue on what might be happening here ??? Did i mention
that querying the Type name of the instance returns the class name in the
namespace created by VS for the Web Reference ? [ as it should ]

Cheers,
Angel
O:]
Jul 21 '05 #1
3 1589
Angelos Karantzalis <ak**********@yahoo.com> wrote:
I've just come across a rather weird problem.

i'm using the following code to get the names of the public properties of an
object:

public static string[] GetPropertyNames(object instance){
Type objType = instance.GetType();
PropertyInfo[] props = objType.GetProperties();
string[] strPropNames = new string[props.Length];
for(int i=0; i<props.Length; i++)
strPropNames[i] = props[i].Name;
return strPropNames;
}

.. that worked fine on framework class instances, and it also worked on my
own classes, even after I'd loaded an assembly dynamically from the file
system.

HOWEVER, now I'm using it to query an instance of a class returned from a
web service. I know that the class has several public properties [duh! I
wrote it !], but the code above doesn't work. It returns a zero-length
string array. A similar function that returns the method names, returns the
classic "object" methods, which is again not correct [quering for the method
names should also return the "get_<public property name>" methods for each
public property ... ]

Does anyone have a clue on what might be happening here ??? Did i mention
that querying the Type name of the instance returns the class name in the
namespace created by VS for the Web Reference ? [ as it should ]


I *believe* that types returned by web services don't have properties -
they just have public fields. Look at the code VS generated for you for
the type to check.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
The objects created by Visual Studio doesn't have properties, it only has
public fields.
You'll either have to change your reflection code to access these fields or
you will have create your own proxy using the WSDL tool and then change the
code to use properties instead.

Anders Norås
blog: http://dotnetjunkies.com/weblog/anoras

"Angelos Karantzalis" <ak**********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi y'all ...

I've just come across a rather weird problem.

i'm using the following code to get the names of the public properties of
an
object:

public static string[] GetPropertyNames(object instance){
Type objType = instance.GetType();
PropertyInfo[] props = objType.GetProperties();
string[] strPropNames = new string[props.Length];
for(int i=0; i<props.Length; i++)
strPropNames[i] = props[i].Name;
return strPropNames;
}

.. that worked fine on framework class instances, and it also worked on my
own classes, even after I'd loaded an assembly dynamically from the file
system.

HOWEVER, now I'm using it to query an instance of a class returned from a
web service. I know that the class has several public properties [duh! I
wrote it !], but the code above doesn't work. It returns a zero-length
string array. A similar function that returns the method names, returns
the
classic "object" methods, which is again not correct [quering for the
method
names should also return the "get_<public property name>" methods for each
public property ... ]

Does anyone have a clue on what might be happening here ??? Did i mention
that querying the Type name of the instance returns the class name in the
namespace created by VS for the Web Reference ? [ as it should ]

Cheers,
Angel
O:]

Jul 21 '05 #3
god .. how could I be so stupid & not check for public fields ... ? That was
it allright ...

Thanks a milion guys, i guess sometimes technology IS a substitute for
stupidity :D

O:]

"Anders Norås" <an**********@objectware.no> wrote in message
news:#6**************@TK2MSFTNGP10.phx.gbl...
The objects created by Visual Studio doesn't have properties, it only has
public fields.
You'll either have to change your reflection code to access these fields or you will have create your own proxy using the WSDL tool and then change the code to use properties instead.

Anders Norås
blog: http://dotnetjunkies.com/weblog/anoras

"Angelos Karantzalis" <ak**********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi y'all ...

I've just come across a rather weird problem.

i'm using the following code to get the names of the public properties of an
object:

public static string[] GetPropertyNames(object instance){
Type objType = instance.GetType();
PropertyInfo[] props = objType.GetProperties();
string[] strPropNames = new string[props.Length];
for(int i=0; i<props.Length; i++)
strPropNames[i] = props[i].Name;
return strPropNames;
}

.. that worked fine on framework class instances, and it also worked on my own classes, even after I'd loaded an assembly dynamically from the file
system.

HOWEVER, now I'm using it to query an instance of a class returned from a web service. I know that the class has several public properties [duh! I
wrote it !], but the code above doesn't work. It returns a zero-length
string array. A similar function that returns the method names, returns
the
classic "object" methods, which is again not correct [quering for the
method
names should also return the "get_<public property name>" methods for each public property ... ]

Does anyone have a clue on what might be happening here ??? Did i mention that querying the Type name of the instance returns the class name in the namespace created by VS for the Web Reference ? [ as it should ]

Cheers,
Angel
O:]


Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steve | last post by:
Hi all If there is a more relevant NG for my question about Reflection I would be grateful if some-one could point me in the right direction! I am using the following code to get the Public...
2
by: Lev | last post by:
Hi, I have some code that does reflection on an assembly I load. When I try to get the attributes on one of the methods implemented in the assembly, the MC++ version does not return anything....
0
by: Shawn Hogan | last post by:
Hi everyone, I've been trying to execute a control's private event code via reflection from another class with the goal of potentially doing some unit testing. The examples below are trying to...
2
by: Marco | last post by:
Hi, I try to use reflection to retrieve class B members and not inherited members. I wonder why the myMember value is nothing. Any suggestions? Thanks Module Module1 Sub Main()
6
by: ECathell | last post by:
I have a routine that compares 2 intances of the same object to see if there are any changes. The problem is that even though there are no changes, it tells me there are. I have even tried running a...
3
by: Angelos Karantzalis | last post by:
Hi y'all ... I've just come across a rather weird problem. i'm using the following code to get the names of the public properties of an object: public static string GetPropertyNames(object...
15
by: satankidneypie | last post by:
Hi, I'm going to start this off with some code as it'll make it easier to explain afterwards... using System; namespace ConsoleApplication1 { /// <summary>
9
by: TS | last post by:
i have code that creates assemblies and classes from the assemlby and methods from the classes to set properties of dynamically created controls. How i should go about validating the assemblies,...
3
by: Steve Amey | last post by:
Hi all I am using reflection to read the values of properties from a class. The class is returned from a Web Service so I have to access the class using FieldInfo (Using VS 2003 which converts...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.