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();
}
Select the method and right-click. Select Quickwatch from the menu.
I'm assuming you cannot put a breakpoint within GetProcedureReport
?
In VS 2013, you can add the variable $ReturnValue to the watch. It contains the actual returnvalue from the function.
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
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