I have a very strange issue with a Reflection. When I try to get the value of a field, which contains list of objects, I get the list.Count == 0
. When I check these values in the watch window during debugging, afterwards I get the list.Count > 0
with the same Reflection method. There are no multithreading between the checks (Thread ID is the same) and no operations being performed, which would clear and refill the list again. I could not reproduce the issue on the clean (testing) project. I use .NET framework 4.0 for compatibility reasons and the following logics in the code:
Type t = cmd.GetType();
FieldInfo[] fi = t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
object[] o1 = null;
if (fi != null)
{
o1 = new object[fi.Length];
for (int i = 0; i < o1.Length; i++)
{
o1[i] = fi[i].GetValue(cmd);
}
}
I would like to know if someone had similar issues and could share with ideas what could have gone wrong and maybe there are solutions how to workaround. To be honest there were few more cases where I could observe the inconsistencies between the debugging information and what the program actually does. For example, once I've encountered a situation where the debug tool had shown the result true
but the if
clause skipped the line as it would have been false
result.
Aucun commentaire:
Enregistrer un commentaire