If you examine C# code in Reflector, you can notice special compiler-generated local variables that are named with the pattern CS$X$Y. These variables were (unofficially) documented in this answer.
Is there any way to view these values via the Watch window in Visual Studio, or via the VS Debugger Extensibility API?
I'm asking specifically about the regular Visual Studio debugger, please do not answer that this is possible via windbg/sos/sosex - as that's not what I'm looking for.
Unfortunately there is no way to do this with the C# EE. The names for these locals are indeed stored in the PDB and available. However the C# EE will filter out all temporary values during debugging to reduce clutter. This filtering is unconditional and cannot be overridden. C# is not alone here as this is the behavior in every language.
The good news though is that every language uses different naming patterns for their temporaries. This means a temporary name in C# will run right past the filtering of the VB EE. Even though it's an illegal identifier the VB EE still considers it a valid local (and vice versa). Hence you just need to temporarily switch the debugging engine for C# code to the VB EE and the locals will become visible
Here is how to do this
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\AD7Metrics\ExpressionEvaluator\{3F5162F8-07C6-11D3-9053-00C04FA302A1}\{994B45C4-E6E9-11D2-903F-00C04FA302A1}
{60F5556F-7EBC-4992-8E83-E9B49187FDE3}
to {59924502-559A-4BB1-B995-5D511BB218CD}
Now whenever you debug C# code it will use the VB EE and hence display temporaries as normal locals. Note that this is completely unsupported. But it should work fine. I was able to see raw closure values with this trick on my machine and poke around a bit without any issues.
Note that these instructions are specific to Visual Studio 2013. If you are using 2012, or 2010 it should work by changing the 12.0_Config in the registry key name to
It may need a few tweaks on top of that (didn't actually test older versions). If you run into any problems there let me know and I'll try and get it working locally and update the instructions
Here is a pic of the final output once you make this change
No, they are not added to the PDB file. The debugger simply has no way to discover them, nor know anything about where they are stored. This is all entirely intentional.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With