8

While debugging a .NET Core console application in VS 2017, I'm unable to make an edit and then set the next statement. It gives me the error mentioned in the title:

enter image description here

For example, if I set the breakpoint where indicated by the comment, then debug, and modify the string in the first line directly above the breakpoint, I get the error:

static void Main(string[] args)
{
    string x = "foo"; // modify this after debug breaks.
    string y = "bar"; // breakpoint here
}

NOTE: this works as expected in a .NET Framework console application.

When I google the title of this OP, I get zero results, even if I split the two sentences from the error message into separate quoted strings. When I google without quotes, I get a number of results that don't provide an an answer. For example, this one is similar in that it starts out with "Unable to set the next statement" but then the rest is different. This one is also similar but again is different after the first sentence.

What is causing this?

itsme86
  • 19,266
  • 4
  • 41
  • 57
rory.ap
  • 34,009
  • 10
  • 83
  • 174
  • Just a hunch, but have you tried toggling your "Enable Edit and Continue" debug option? I really have no idea if that's related, but something I'd check. – itsme86 Nov 19 '18 at 16:51
  • Thanks for the suggestion. I just tried it and it didn't change the behavior. – rory.ap Nov 19 '18 at 17:14
  • Are you directly modifying the code, or modifying "x" in the Immediate Window? I am not sure of your original problem, but maybe that would be a helpful workaround? You should be able to type 'x = "newFoo"' in the Immediate Window. – Cardi DeMonaco Jr Nov 19 '18 at 17:57
  • 2
    I'm directly modifying it. Your workaround didn't work but it did lead me to another workaround, which was to set the next line first and *then* modify the value of `x`. It doesn't work when I modify `x` and then try to set the next line. – rory.ap Nov 20 '18 at 13:10
  • 2
    Can anyone repro this? Or is it just me? – rory.ap Nov 20 '18 at 13:10
  • 2
    Having the same issue (VS 2019). Has anyone figure it out? – adinas Jun 04 '19 at 11:26

2 Answers2

1

I had exactly the same error message. I don't know why it worked but I resolved it by:

  1. Checking Options->Debugging->General->Use the legacy C# and VB expression evaluators.
  2. Running a debug session (where I could then edit and continue).

After unchecking the flag again everything was still working.

Matt B
  • 8,315
  • 2
  • 44
  • 65
0

Try this:

  1. Delete the output folder (bin\debug).
  2. Close the IDE.
  3. Open the Project again.
  4. Run the project.

Sometimes Visual Studio IDE lock a file. Or try running Visual Studio IDE as administrator.