Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am developing a WindowsForms application, using the PropertyGrid and new .NET Framework 4.6. My custom control has the PrepareReadOnlyBrowsableProperty method to modify 'Readonly' and 'Browsable' atrributes of its properties:

C#
protected void PrepareReadOnlyBrowsableProperty(string propertyName,
                                                bool readOnly, bool browsable)
{
PropertyDescriptor descr = TypeDescriptor.GetProperties(this.GetType())[propertyName];

// ReadOnly
var attr = (ReadOnlyAttribute)descr.Attributes[typeof(ReadOnlyAttribute)];

FieldInfo field = attr.GetType().GetField("isReadOnly",
                  System.Reflection.BindingFlags.NonPublic |                                               
                  System.Reflection.BindingFlags.Instance);

field.SetValue(attr, readOnly);

// browsable
var attr3 = (BrowsableAttribute)descr.Attributes[typeof(BrowsableAttribute)];

FieldInfo field3 = attr3.GetType().GetField("browsable",
                                       System.Reflection.BindingFlags.NonPublic |  
                                       System.Reflection.BindingFlags.Instance);

field3.SetValue(attr3, browsable);
}


The problem is the following. When I try to debug by steps (operands instructions) the above-mentioned method, the debugger stops at the first line, and then jumps to the line “var attr3 = ...”. Why does it happen (several operands instructions are skipped)?

In the Build page of my application, the configuration is set as “Active (Debug)”, the checkbox "Define DEBUG constant" is checked, the checkbox "Define TRACE constant" is checked, and the checkbox 'Optimize code' is UNCHECKED (turned off).

Thank you in advance.
Posted
Updated 2-Aug-15 11:32am
v4
Comments
Sergey Alexandrovich Kryukov 2-Aug-15 17:00pm    
Those are not "operands". According to your description, skipped are instructions. Normally, nothing should be skipped. Make sure you switch off the optimization. It's the best to debug the configuration "Debug" usually predefined by project templates. If you don't have it, create a configuration with option suitable for debugging.
—SA

1 solution

If debugging goes wrong (as you describe above), I usually go this approach:
1) close and restart Visual Studio, rebuild the solution, try debugging again
2) if no success, check if the produced PDB file is created every time
3) if this is the case, check the debug tab in the project settings: do you start an external program that is located elsewhere where old/no PDB file is located
4) if you try to debug into a library that is not rebuilt from source every time, the library might be compiled as optimized and the PDB also matches the optimized code - i.e. step further in the debugger, since the sequence of control flow might have changed...
5) if the library is part of the rebuild, it might still be rebuild with optimizing settings. See the Solution's Configuration Manager settings if you rebuild in "Debug" rebuilds all dependent projects as "Debug" too.
6) Check in the tools - options - debugging: if you have an alternative source path set, i.e. the sources might be "old" ones

Note: the PDB file contains information that maps IL instructions to source line numbers. If anything in this relation is broken (out-dated PDB, references to out dated sources, etc.), then the debugger cannot display proper source level information. You might debug in Disassembly level too. By default, you see the sources and the CPU instructions interleaved. Even if you don't understand the CPU instructions, you might see if the code is in use.

Regards
Andi
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Aug-15 1:29am    
Good points, a 5.
—SA
Andreas Gieriet 3-Aug-15 11:46am    
Thanks for your 5, Sergey!
Cheers
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900