You can track Out of Scope Objects by assigning an Object ID during debugging in Visual Studio

You can track Out of Scope Objects by assigning an Object ID during debugging in Visual Studio

Make Object ID”, you can consider it as an another hidden features of Visual Studio that can give you lot of flexibility during debugging.  When we set “Make Object ID” for an object,  we are informing the Debugger to keep track of that object no matter it’s within scope or out of scope for the current context.  You can create the “Object ID” either from Locals, Autos or from Watch Windows. Object ID is a integer number prefix by a dollar ($) sign. When we create Object ID for an particular object, Visual Studio Debugger  use an integer value to uniquely identify the object. This “Object ID” allows you to get the object details even if it is out of scope.

 

image

 

 

Let’s try to understand with a very simple example, where we are iterating a set of string through a loop. If you inspect the value of “item” for first time it should be “name1”.

image

Now If you move to next items, there is no way to get the value of previous items. In that case you can just select “Make Object ID” for the selected object.

NOTE : This is a very simple object, You can apply this for any complex objects as well.

 

image

Object the Object ID is created, a $ < Value> will be added with the item.

Must Read :  How to use out of scope object with in Conditional Breakpoint ?

 

image

Now, Let’s think you move to the next item in the collection.

image

Now, to access the previous value you can just type “$1” and it will show the value of previously tagged item associated with this object id.

image

Isn’t it cool.  Just think about you want to try to access one object’s values which is already went out of scope. This is super powerful feature during debugging; You can even object / values across methods / modules.

Think about this following add-on. Your context moved to anther method, and there if you try to access “item” values; you will get message that “item” does not exist.

image

But, instead, when you are trying to access it with object it you have it live.

image

 

Refer to my one of detailed post the same subject line  How to track an object which is Out of Scope while Debugging ?

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

3 Comments to “You can track Out of Scope Objects by assigning an Object ID during debugging in Visual Studio”

Comments are closed.