Or Kedmi
Or Kedmi

Reputation: 57

C# Reflection at run-time

I want to get information about the fields, functions and threads of a some project, through another project.

As an example project that I want to explore, I created a field int x that initialize to 1. The Main calls to function that changes the value of x to 2. I stuck the Main in an endless loop. I ran this project.

The second project: Get the path to the EXE file of the first project, and load the assembly. By reflection, i got the names of departments, functions and fields. I tried to print the value of the field x by the function getValue. Instead of printing 2, 1 was printed. i.e., the reflection refers to the values of the compiled-time, instead of the run-time.

what should i do?

Upvotes: 1

Views: 199

Answers (1)

dutzu
dutzu

Reputation: 3910

You can't get the new value, that's in memory, in the other process.

With Reflection you can however load that assembly, create an instance of that class and call Main explicitly and then check for the value of the int because then the code would be run by your process.

Do not expect to be able to sniff the values out of the memory space of another application with Reflection, that is not what Reflection does.

Upvotes: 4

Related Questions