Problem with debug watch in Visual Studio with yield return enumerator methods
- by Stuart
I have a method which returns an IEnumerable<> which it builds up using the yield return syntax:
public IEnumerable<ValidationError> Validate(User user)
{
    if (String.IsNullOrEmpty(user.Name))
    {
        yield return new ValidationError("Name", ValidationErrorType.Required);
    }
    [...]
    yield break;
}
If I put a breakpoint in the method, I can step over each line, but if I try to use the Watch or Immediate windows to view the value of a variable I get this error:
  Cannot access a non-static member of
  outer type '[class name].Validate' via
  nested type '[class name]'
Does anyone know why this is and how I can get around it?