473,320 Members | 1,799 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.

Help ! Why isn't this working?


I've read the docs and evrything seems fine. Then what I am missing ?
This is the code snippet:
try
{
Assembly LAssembly = Assembly.LoadFrom(args[0]);

Type[] LTypes = LAssembly.GetTypes();

foreach (Type LType in LTypes)
{
if (LType.IsClass)
{
Console.WriteLine ("Type Name : {0}", LType.FullName);

try
{
foreach (FieldInfo LFieldInfo in
LType.GetFields(BindingFlags.Public | BindingFlags.NonPublic))
{
Console.WriteLine ("{0}", LFieldInfo.Name);
}
Console.WriteLine("__");
}
catch (Exception LEx)
{
Console.WriteLine(LEx.Message);
}
}

}
}
catch (Exception LEx)
{
Console.WriteLine(LEx.Message);
}

The assembmly is ok, i get all types in it listed but I can't list the
fields! What am I missing ????
Christina Androne
Nov 15 '05 #1
6 1660
Christina Androne <ac********@home.ro> wrote:
I've read the docs and evrything seems fine. Then what I am missing ?


You haven't specified BindingFlags.Instance or BindingFlags.Static.

<snip>

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Hi Christina,

The error is in the call to GetProperties:
LType.GetFields(BindingFlags.Public | BindingFlags.NonPublic))

From MSDN:

You must specify Instance or Static along with Public or NonPublic or no
members will be returned.

So if you change the above line by:
LType.GetFields(BindingFlags.Public | BindingFlags.NonPublic
|BindingFlags.Instance ))

you should get the result you want.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Christina Androne" <ac********@home.ro> wrote in message
news:es**************@TK2MSFTNGP12.phx.gbl...

I've read the docs and evrything seems fine. Then what I am missing ?
This is the code snippet:
try
{
Assembly LAssembly = Assembly.LoadFrom(args[0]);

Type[] LTypes = LAssembly.GetTypes();

foreach (Type LType in LTypes)
{
if (LType.IsClass)
{
Console.WriteLine ("Type Name : {0}", LType.FullName);

try
{
foreach (FieldInfo LFieldInfo in
LType.GetFields(BindingFlags.Public | BindingFlags.NonPublic))
{
Console.WriteLine ("{0}", LFieldInfo.Name);
}
Console.WriteLine("__");
}
catch (Exception LEx)
{
Console.WriteLine(LEx.Message);
}
}

}
}
catch (Exception LEx)
{
Console.WriteLine(LEx.Message);
}

The assembmly is ok, i get all types in it listed but I can't list the
fields! What am I missing ????
Christina Androne

Nov 15 '05 #3
Jon Skeet [C# MVP] wrote:
Christina Androne <ac********@home.ro> wrote:
I've read the docs and evrything seems fine. Then what I am missing
?


You haven't specified BindingFlags.Instance or BindingFlags.Static.

<snip>


I did :( ... It's not working :( ... I've tried all sort of flags, not
to mention the GetFields() method. I copypasted the last thing I tried,
that's why it was without the BindingFlags.Instance.
Christina Androne
Nov 15 '05 #4
Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi Christina,

The error is in the call to GetProperties:
LType.GetFields(BindingFlags.Public | BindingFlags.NonPublic))

From MSDN:

You must specify Instance or Static along with Public or NonPublic or
no members will be returned.

Thanks a lot for your answer, but I tried that. Please see the my reply
to Jon.

Christina Androne
Nov 15 '05 #5
Christina Androne <ac********@home.ro> wrote:
Jon Skeet [C# MVP] wrote:
Christina Androne <ac********@home.ro> wrote:
I've read the docs and evrything seems fine. Then what I am missing
?


You haven't specified BindingFlags.Instance or BindingFlags.Static.

<snip>


I did :( ... It's not working :( ... I've tried all sort of flags, not
to mention the GetFields() method. I copypasted the last thing I tried,
that's why it was without the BindingFlags.Instance.


Did you try with *all* of:

BindingFlags.Instance |
BindingFlags.Static |
BindingFlags.Public |
BindingFlags.NonPublic

in the same run?

If you could put it in a short but complete program which demonstrates
the problem (eg listing the fields of a single test type, for
simplicity) that would help.

See http://www.pobox.com/~skeet/csharp/complete.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
Hi Chistina,

This may seems a rather silly question, but ..
Does the class has any field?
I tried this with a class with several properties and it worked fine
changing GetField by GetProperties and it worked fine
I now tried this code below and it also worked fine:

class A
{
public int a;
public int c;
public int b;
}

Type LType = typeof(A);

if (LType.IsClass)
{
Console.WriteLine ("Type Name : {0}", LType.FullName);

try
{
foreach (FieldInfo LFieldInfo in
LType.GetFields(BindingFlags.Public | BindingFlags.NonPublic|
BindingFlags.Instance))
{
Console.WriteLine ("{0}", LFieldInfo.Name);
}
Console.WriteLine("__");
}
catch (Exception LEx)
{
Console.WriteLine(LEx.Message);
}
}
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Christina Androne" <ac********@home.ro> wrote in message
news:eX*************@TK2MSFTNGP10.phx.gbl...
Jon Skeet [C# MVP] wrote:
Christina Androne <ac********@home.ro> wrote:
I've read the docs and evrything seems fine. Then what I am missing
?


You haven't specified BindingFlags.Instance or BindingFlags.Static.

<snip>


I did :( ... It's not working :( ... I've tried all sort of flags, not
to mention the GetFields() method. I copypasted the last thing I tried,
that's why it was without the BindingFlags.Instance.
Christina Androne

Nov 15 '05 #7

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

Similar topics

4
by: mr_burns | last post by:
Hi there, I am tryin to use a $_POST variable but the name of the form element is dynamic. Below is the code I am tryin but is obviously wrong as it isnt working: $abc = $_POST; //isnt...
2
by: Tomislav Lepusic | last post by:
Hello, I don't know if this is the right group (I'm more in Perl, know nothing about Python), so if you can help me thanks, if not, sorry to bother you. I'm working on my student project and...
8
by: Mike Gifford | last post by:
Hello, I've got a number of html fragments (in a template file) which are bundled together in a cms. I'm sure that there's a way through javascript to convert a piece of code like this: ...
1
by: Sunshine | last post by:
Pretty new to javascript so please help. Why isn't this working in my validateform()? if (document.This.strOld.value.compareTo(Session("strPassword")) != 0) { alert("Current password...
20
by: Jack Schitt | last post by:
I thought I was starting to get a handle on Access, until I tried doing something useful...now I'm stuck. I have a DB with two tables - to keep it simple I'll say that one is an Employee File...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
7
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
8
by: manmit.walia | last post by:
Hello Everyone, Long time ago, I posted a small problem I had about converting a VB6 program to C#. Well with the help with everyone I got it converted. But I overlooked something and don't...
12
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.