58

I am able to edit my code in debug mode but then pop up shows the error that

Edits were made which cannot be compiled. Execution cannot continue until the compile errors are fixed

but error list is empty and i have checked enable edit and continue.

I am using vs2010.

Cleaning and restarting has not solved the problem.

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
vivek verma
  • 1,716
  • 1
  • 17
  • 26

11 Answers11

40

This problem can occur when your workspace broke. Just close Visual Studio, delete (or better first just rename) the .vs folder and start Visual Studio again.

It can even happen with VS2017.

Jack Miller
  • 6,843
  • 3
  • 48
  • 66
16

In Visual Studio

Debug --> Options --> Debugging --> General --> uncheck Enable Edit and Continue
ru4ert
  • 998
  • 2
  • 14
  • 25
  • This worked for me, although I also had to stop debugging first ( https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-enable-and-disable-edit-and-continue?view=vs-2019 ). Note that I wasn't interested in Edit-And-Continue in the first place. I just wanted to stop this error from coming up when I edited code while debugging. – Brian Rothstein Nov 01 '21 at 23:29
6

I had the same problem (VS2017), for me it was enough to menu item Build and click Clean Solution Then Rebuild Solution and everything worked fine again.

wecky
  • 754
  • 9
  • 17
  • Deleting ".vs" folder did not work but simply "Clean Solution" was enough (no need to explicitly "Rebuild Solution". – Corey Alix Apr 12 '21 at 15:15
5

Potentially this is caused by Visual Studio's Edit & Continue feature.
A workaround is to disable this feature:

Debug --> Options --> Debugging --> General --> uncheck Enable Edit and Continue

Solution taken from here.

Also answered here.

veuncent
  • 1,599
  • 1
  • 20
  • 17
  • Is there a real solution of the problem? – Goldi Dec 06 '19 at 08:51
  • 1
    Edit and Continue is not a ReSharper feature. – GaussZ Jan 07 '20 at 13:55
  • You are right, it is a Visual Studio feature. Hardly worth a downvote though, @GaussZ – veuncent Jan 17 '20 at 08:27
  • Same error (on v16.11.9) just occurred after a VS hang and crash. Restarted PC. Issue persists. There is a warning `"Feature: 'Edit and Continue' is currently unavailable due to an internal error. Show Stack Trace."` which then displays the error: _"Microsoft.ServiceHub.Framework.ServiceActivationFailedException : Activating the "Microsoft.VisualStudio.LanguageServices.EditAndContinue64" service failed. ---> System.UnauthorizedAccessException : Access to the path is denied._ [truncated] ***Disabling*** **Enable Edit and Continue** worked - but can't be a REAL SOLUTION. – Jonno Feb 08 '22 at 10:00
4

I've had this problem with Visual Studio 2008, 2010, and 2013. I wrote a batch file I keep in the solution folder for each of my projects when this problem crops up. Expanding on what Vijay said, this cleans out the bin and obj folders. Sometimes Visual Studio will have the folders locked and I have to close it, but after I clear these out the problem goes away... for a while. I'm not sure of the underlying cause, I believe the binaries and the code in memory is somehow getting out of sync. But this allows a quick close, clean, open solution.

@echo off
cls
dir bin /s /AD /b > clean.tmp
dir obj /s /AD /b >> clean.tmp
for /F  "tokens=*" %%A in (clean.tmp) do echo rmdir /S /Q "%%A" 
echo This command will remove ALL BIN and OBJ folders in this tree.
echo To run the commands as listed ...
pause
for /F  "tokens=*" %%A in (clean.tmp) do rmdir /S /Q "%%A" 
del clean.tmp
pause
Billy Willoughby
  • 806
  • 11
  • 15
  • None of the solutions above this one specifically fixed the problem. After I ran this script, it fixed. It may also have been a combination of doing all-of-the-above. – Doug Null Jun 10 '20 at 14:05
  • Thanks, this worked for me. Wonder if cleaning the solution works- it deletes everything in Bin and Obj directories but not the directories themselves. – Sanjay Subramaniam Feb 03 '23 at 13:24
  • 1
    @SanjaySubramaniam Greetings sir; At the time I wrote this, cleaning did not resolve the problem. It's been a few years, but I think it would say clean, but then the files were still there. Glad I could help. – Billy Willoughby Feb 03 '23 at 19:24
4

I had this problem as well in a c# project. It turns out it was because I had recently enabled the "Enable native code debugging" option.

Turning it off restored the functionality.

Willster419
  • 114
  • 1
  • 7
  • Mixed mode debugger doesn't (apparently, because setting to Managed only fixes it) allow Edit and Continue on managed code. – Alan Baljeu Dec 11 '20 at 16:30
  • Could you more clear about the issues. I have tried in many combination but not resolved. – Palash Kanti Bachar Mar 03 '21 at 06:36
  • @PalashKantiBachar what do you mean? I would get the same window as OP and found it was because of the "Enable native code debugging" option in a c# managed code project. – Willster419 Mar 04 '21 at 15:56
  • @Willster419 Thanks for the response, I had also tried the same way (Using vs2019 latest version and .net core) but failed to get the success. If I change the code during debugging it's not working. – Palash Kanti Bachar Mar 05 '21 at 07:20
3

There seems to be a regression in Visual Studio 2019 16.9 that affects this features. If you are experiencing this issue check https://developercommunity.visualstudio.com/t/Edits-were-made-to-the-code-which-canno/1370525#T-ND1386337 in order to know when the fix will be available. For Enterprise/Professional versions, a downgrade to 16.8 would be advised. Hope this helps people experiencing this bug (like myself) since this is the first SO post that comes out in searches.

Franky
  • 31
  • 1
1

There is another possible culprit:

It may be a problem with one of the projects that are included in the solution.

I had the exact same problem, as did a co-worker of mine, and the culprit was one of the projects in our .sln file; a WinForms application that was also started in connection with several other projects in the same solution file.

The remedy was simple:

Remove the WinForms project from the solution, and start a separate Visual Studio instance, where the WinForm project was separated from the rest. And then it worked. I think there is some file edited when the WinForms application was run, that changed the code, for some reason.

Ted
  • 19,727
  • 35
  • 96
  • 154
0

I am using Visual Studio 2017 Community updated as to date.

After hours spent trying all the solutions posted in this thread highlighted by Hao Nguyen in the comments above, the only solution that worked was to remove the Workspace and Map&Get again.

To remove the Workspace, FileSource controlAdvancedWorkspaceRemove.

tval
  • 412
  • 3
  • 17
alelom
  • 2,130
  • 3
  • 26
  • 38
0

Sorry for a bit late answer but might be it can help out some other technologist. I had faced the same issue in my VS2019 & VS2022 and find 2 solutions.

Solution 01:

i. Tools/Debug => Options => Debugging => General --> Enable Edit and Continue [uncheck it]

ii. Rebuild Code

iii. Tools/Debug => Options => Debugging => General --> Enable Edit and Continue [check it again]

Solution 02:

i. Close your Visual Studio.

ii. Delete the .vs hidden-folder (For safe side, rename it instead to delete)

iii. Reopen your Visual Studio and run the project again.

Hope it'll work!

Arsman Ahmad
  • 2,000
  • 1
  • 26
  • 34
-1

This type of error message could occur in three categories as I know so far:

  1. Visual Studio setting, like you have to set Visual Studio IDE environment properly
  2. Source control related
  3. Your method of code does have an interop related API that doesn't like to be edited in the debugging mode

Most people could fix their problem by going through #1. To make sure if your Studio setting is right, simply run a new and very small solution, and edit it in debugging mode. If that gives you the same error message, then your problem is with Bill Gates:), go fixing the configurations. If no error, shift focus to your own code.

Try to edit in debugging mode in a separate method in your solution. This error could be method dependent if the critical part is not in the global area. After narrowing down the problem to a method, well, you are close to a good luck. Commenting out most or all contents in the method, and gradually un-comment the lines. You will eventually ping down to the point where the problem gets triggered.

In my case, it is the Excel file application that caused the problem. The solution: I created the objects of Excel app, workbook, and worksheet as global variables, and open and defined them in one of my main method. Somehow, after doing so, Bill Gates doesn't like to me fool around the method any more in debugging mode. My trick to go around Bill is to write the workbook opening and worksheet definition in a small separate method, and just call that it from the original method. After that, I can happily edit any part in the big method during debugging run time! Still, I cannot do that in that small method that just contains the workbook and worksheet handling. Well, that is Bill's comfortable work place:) I don't need to.

Bob
  • 1
  • 1