0

In Visual Studio 2013 how i can find out the value returned by a method which is not being stored anywhere.

Lets assume the methods are in a DLL which i don't have the source code so i cannot set a break point at the return line.

Example Use Case 1:

if(GetEnumResponse() == MyEnums.MyValue)
{
   // Do Stuff
}

Example Use Case 2:

var Response = (MyResponse)GetResponse();

In example 1, if im expecting the condition to be true but it is false, how can i use the debugger to find out what the result of GetEnumResponse() is?

In example 2, if the cast is causing an invalid cast exception how can i view what the result of GetResponse() is?

CathalMF
  • 9,705
  • 6
  • 70
  • 106
  • @Frédéric - I don't think http://stackoverflow.com/questions/9375551/debug-return-value is a duplicate. The OP can't see the source for the methods they're trying to see the return value of so they can't set a break point on the return. – ChrisF Dec 15 '15 at 10:26
  • @ChrisF, according to [this link](http://blogs.msdn.com/b/visualstudioalm/archive/2013/06/27/seeing-function-return-values-in-the-debugger-in-visual-studio-2013.aspx) from the duplicate, the questioner should be able to observe the values returned by intermediary functions in the Autos pane, even if they cannot break at the `return` statements in the functions themselves. Am I missing something? – Frédéric Hamidi Dec 15 '15 at 10:29
  • @FrédéricHamidi. Hmm. Tricky. The question itself isn't the same and the main part of the solution doesn't help, but that aspect does. Not sure what the correct solution is. – ChrisF Dec 15 '15 at 10:31
  • You should look at [OzCode](http://www.oz-code.com/). – Lasse V. Karlsen Dec 15 '15 at 11:19

2 Answers2

1

The simplest solution is to change how you call the methods to put the return value into a local variable which you can interrogate.

Case 1:

var result = GetEnumResponse();
if (result == MyEnums.MyValue)
{
   // Do Stuff
}

Case 2:

var result = GetResponse();
var Response = (MyResponse)result;

You can even leave this code in production if you want as it is functionally equivalent to what you have now.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • Yes of course thats the obvious solution but in the case im debugging through a huge project. If i make changes like this everytime i want to see its value then i need to build and deploy to my test environment which takes about 10 minutes of my time. – CathalMF Dec 15 '15 at 11:13
1

You can use the Immediate (Debug -> Windows -> Immediate) in Visual Studio. Here you can evaluate expressions and see the result.

The return value of a function is displayed in the Autos tab or you can use the $ResultValue in the immediate window when the function has returned.

See points 6 and 7 on this blog post about seeing function return values in the debugger

ChrisF
  • 134,786
  • 31
  • 255
  • 325
AntiHeadshot
  • 1,130
  • 9
  • 24