Brad at the PFE Developer Notes for the Field blog shares news of Caller Information, a new feature in Visual Studio 2012:

One of the new features is the concept of Caller Information, available in both C# and VB.  Caller Information allows you to obtain certain information about the caller to a method.  More specifically, it allows you to get the name of the calling method as well as the source file information and line number.

The use case described looks, well, useful!

Let’s say MyFunc takes an argument or two, and occasionally MyFunc gets an exception when using the arguments – for example, a NullReferenceException.  But the fact that MyFunc doesn’t reproduce this exception consistently may make it difficult to determine what the code path is that results in the exception.

If MyFunc captured the calling function, you’d have a much better idea of how to reproduce the problem and, therefore, find root cause and a resolution.

There’s some sample code that shows a quick demo of getting to this information too.

Looks like a very nice feature to have, without having to get into try/catch blocks to document where you’re at for debug logging.


Posted by Tristan Kington, MSPFE Editor