Unable to set next statement when debugging

2019-04-12 11:16发布

问题:

I am debugging my project in VS2015 and an exception is thrown in my code. When I try to set the next statement I get the error message displayed below. When I debug the same solution in VS2013 I am able to set the next statement without any problems. This behavior seems to occur for multiple kinds of exceptions.

Example code that I can reproduce the problem with is shown below. When an exception is thrown on the last line in TestMethod1 I can easily move back to the 1st statement in VS2013 but not in VS2015.

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        object o = new object();
        o = null;
        var e = o.ToString();
    }
}

回答1:

In Exception Settings, you need to enable Break When Thrown for the particular CLR exception type that is being thrown, or <All Common Language Runtime Exceptions not in this list> for custom exceptions. In this particular example, enabling System.NullReferenceException should allow you to set next statement as expected.

If there are particular custom exceptions you want to break on without breaking on all unlisted CLR exceptions, you can add them to the list in Exception Settings and choose accordingly.

I asked about this on MSDN and am relaying info from there. [Source]