Unable to set next statement when debugging

user1151923 picture user1151923 · Sep 8, 2015 · Viewed 10k times · Source

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.

Microsoft Visual Studio error window: "Unable to set the next statement. The attempt to unwind the callstack failed."

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();
    }
}

Answer

Kate Bedenbaugh picture Kate Bedenbaugh · Sep 29, 2015

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]