Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the return value while debugging?

I looked through SO but couldn't find the answer, I'm sure it's there though...?

While debugging, how do I get the value of the return statement if I put a breakpoint on it? I like to condense to a single line just so it looks "pretty". But I currently don't since I can't figure out how to debug the returned result...?

using (IUnitOfWork context = new EFUnitOfWork())
{
    var repo = new ReportRepository(context);
    return repo.GetProcedureReport(startDate, endDate).ToList();
    //return result.ToList();
}
like image 802
MisterIsaak Avatar asked Mar 04 '13 22:03

MisterIsaak


3 Answers

Select the method and right-click. Select Quickwatch from the menu.

enter image description here

I'm assuming you cannot put a breakpoint within GetProcedureReport?

like image 145
IAbstract Avatar answered Oct 25 '22 07:10

IAbstract


In VS 2013, you can add the variable $ReturnValue to the watch. It contains the actual returnvalue from the function.

like image 36
Jesper Jensen Avatar answered Oct 25 '22 06:10

Jesper Jensen


The type of return value debugging you're attempting is simply not possible with managed languages like C#. The C++ debugger provides this information, via the autos window, but not managed languages.

The primary reason why is that the CLR debugging engine simply doesn't provide this value. For C#, VB or F# to provide this they would need to rewrite every return statement to spill the value into a temporary and then return the temporary. Return value debugging could then be achieved by surfacing this temporary in the debugger.

var returnTemp = repo.GetProcedureReport(startDate, endDate).ToList();
return returnTemp;

This would work but it would provide negatives to the code. Most notably that big struct values would end up being copied twice and contribute negatively to performance. Additionally this rewrite would need to occur at compile time and would affect every method being compiled. It would be much less impactful if it could be done on demand at debug time. The negatives just out weigh the benefits here.

Note that VB.Net does provide return value debugging to a small degree. I've blogged about how that works here

http://blogs.msdn.com/b/jaredpar/archive/2011/01/12/why-the-debugging-difference-between-c-and-vb-net-return-values.aspx

like image 21
JaredPar Avatar answered Oct 25 '22 06:10

JaredPar