Problem with debug watch in Visual Studio with yield return enumerator methods

Posted by Stuart on Stack Overflow See other posts from Stack Overflow or by Stuart
Published on 2010-05-28T08:14:56Z Indexed on 2010/05/28 8:22 UTC
Read the original article Hit count: 243

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?

© Stack Overflow or respective owner

Related posts about visual-studio-2008

Related posts about debugging