47

The Visual Studio Edit and Continue feature stopped on Visual Studio 2010, and I don't know what has caused the problem.

I am working on a Windows application program using C#. This application was initially developed in Visual Studio 2008, and later upgraded to Visual Studio 2010.

Everything was working fine, including Edit and Continue, until I upgraded the .NET Framework from 3.5 to 4.0.

Now when I use debug mode, changing any line of the code in the IDE results in the following message:

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

Actually, there are no compilation errors, and I must restart the Visual studio to get the updates to run.

How can I get Edit and Continue to work again?

CJBS
  • 15,147
  • 6
  • 86
  • 135
Cracker
  • 916
  • 2
  • 7
  • 16
  • have you tried reinstalling visual studio or the .net framework 4? – Daniel Casserly Jan 24 '11 at 12:42
  • 3
    no I'm still trying to figure out the problem – Cracker Jan 24 '11 at 12:52
  • Are you *positive* that no compiler error was detected? I've never seen this behavior before, and I'm suspicious of its reproducibility. – Cody Gray - on strike Jan 24 '11 at 13:42
  • I've come across same problem with VS 2012. Pretty sure that I've got no compiler error (stopping and debuging again works perfectly fine), but I completely lost VS edit and continue as it presents exactly that error message. – Joel Dec 06 '13 at 11:12
  • Ive gotten this error as well when working with multiple people who have some modified settings. It comes and goes, but Edit and Continue is always enabled. Seems to come and go. I would encounter it even when adding a comment to my code. – Ben Sep 06 '17 at 18:33
  • I added an answer. I had to rename one of my class files. You can not have two files with the same .cs filename in the same project or continue and edit doesn't work with .net core 3.1 – PHPGuru May 11 '21 at 19:20

23 Answers23

46

In the Solution Explorer view, right-click on each reference of References, choose Properties. In the Properties view, sign False to the field of Embed Interop Types. This works for me.

Dianyang Wu
  • 461
  • 1
  • 4
  • 2
  • i had added a new reference, and it had stopped working right after that. sure enough, Embed Interop Types was set to True by default, and setting it to False worked! Thank you!! – sbenderli Jan 20 '12 at 17:13
  • I also had this exact same problem and this was the fix for me. – Joel Barsotti Feb 01 '12 at 08:43
  • I only had two references with Embed Interop Types = True and when I changed them to False it worked. Thanks! – Torre Lasley May 18 '12 at 14:46
  • 1
    Hmm... I have this problem as well, however, my colleague can Edit and Continue with the same reference set to true. Why would this work on one machine and not another? (Same solution, same line of code!) – skimania Nov 26 '12 at 15:48
  • This is the answer I was looking for. I wasn't using the dynamic keyword like "cracker" (accepted answer) – Riki Jun 09 '13 at 21:20
  • The last comment when I am writing this asked why the same referenced assemblies that have true for Embed Interop Types work on some machines and not others. I've noticed this across projects referencing the same assemblies on the same machine. I had a working project where Edit and Continue worked fine and I tried to make everything the same on the project that would not let me edit and continue. Nothing was working until I found this post. I work with a lot of hardware so I have references to the different instrument dlls all over the place. – Grant Johnson Aug 27 '13 at 14:34
  • 6
    A text search for `True` across the solution may save a lot of time. – Saintali Sep 04 '14 at 21:16
  • I don't have 'EmbedInteropTypes' anywhere in the solution and no use of dynamic keyword - still experiencing the issue. Rebuilding the solution fixes it but only temporarily. – bokibeg Jun 12 '17 at 12:05
20

The Edit and Continue feature does not work with the dynamic keyword.

I tried to remove the method that uses a dynamic parameter, and the converted project now works on Visual Studio 2010.

Internet research reveals that is is a bug that has been reported to Microsoft. The link below has more details:

CJBS
  • 15,147
  • 6
  • 86
  • 135
Cracker
  • 916
  • 2
  • 7
  • 16
  • You should flag this answer as correct (since it's the best one, doesn't matter that it's your own answer). Also, just so that you're aware, if you want to write respond in a comment to someone you should use the `@username` syntax you might have seen in other comments, that way they'll get notified of your responses. – Hans Olsson Jan 24 '11 at 14:29
5

I had some Excel file "embed interop types" == true. When I changed it to false, edit and continue started working.

Josh Darnell
  • 11,304
  • 9
  • 38
  • 66
Jazz
  • 61
  • 1
  • 1
5

I had used Microsoft's profiler yesterday and afterwards my "Edit and continue" feature got away. I finally realized after hours of frustration that I needed to execute VsPerfCLREnv /globaloff command from command prompt and restart my computer. Now I have my Edit and continue future back. It has nothing to do with target platform by the way. It works with target platform set to Any CPU without any hassle.

Adi Lester
  • 24,731
  • 12
  • 95
  • 110
user1690792
  • 51
  • 1
  • 1
  • I experienced this issue in VS 2013. "VsPerfCLREnv /off" (and rebooting) worked for me. I found this program in "c:\Program Files (x86)\Microsoft Visual Studio XXX\Team Tools\Performance Tools" (XXX is the VS version number). – Mark Miller Oct 27 '14 at 20:59
5

I understand this post is old, but I had this issue lately, and this blog post shows me how to fix it.

  • Delete the obj folder
  • Delete the bin folder. You can copy and paste libraries, data files, etc...back to the folder after removal.
  • From VS, menu Solutions -> Clean solution.

This works for me multiple times.

Hao Nguyen
  • 528
  • 4
  • 10
4

I had this problem in Visual Studio 2013, and :-

  • Sometimes just closing and reopening the solution works, but when that doesn't
  • restarting Visual Studio (Close solution, exit Visual Studio, Re-open Visual Studio, re-open solution, re-try debugging with Edit & Continue) fixes it.

In my case, I didn't have any Interop types that were embedded, nor did any of my code have the dynamic keyword, and I had performed a full solution clean without success. I had been running, debugging and re-starting many times, however, so it may have had something to do with memory -- it took Visual Studio more than one minute to close, during which time the disk was thrashing (presumably memory paging at play).

CJBS
  • 15,147
  • 6
  • 86
  • 135
2

In my situation, someone added a Reference to the Project's output into the Reference list: in Solution Explorer look under [ProjectName]\References for [ProjectName*] and remove it.

If the project is relying on code from a copy of itself, you can't 'Edit and Continue'. In the warning list you may or may not (more likely to in a larger project) have 'conflicts with imported type' messages if this is the cause of the problem.

CJBS
  • 15,147
  • 6
  • 86
  • 135
Griknok
  • 384
  • 2
  • 13
  • Thanks for pointing this out. I'm working with a WinForms project that has an Active X control on it. When I drop the control named CableEye.ocx into my form it adds two references to my project called AxCableEyeCtl and CableEyeCtl that both reference the project obj folder in their path variable. Maybe WinForms projects with Active X controls are an automatic no go for 'Edit and Continue' functionality? I'm very inexperienced with Active X controls but I thought it might be worth at least being aware of. – Grant Johnson Oct 09 '20 at 16:10
2

I tried all the above solutions none of them worked for me. However, when I deleted the bin and object folders in visual studio and run again, it start to work.

2

I'd try cleaning out all the files that are generated by VS. So I'd delete the bin and obj directories and I'd also delete the *.suo and *.user files. Since those files are auto-generated this shouldn't affect anything (though I'd obviously make a backup of all files just in case there's some other files that have been put in there by mistake).

Sometimes those files can get corrupted (it used to happen quite a lot in the old VC++ etc) and then VS can start acting very funny.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
  • 1
    I did and the problem still exist. – Cracker Jan 24 '11 at 12:59
  • @cracker: I'd try the following: Change the project back to 3.5 (just to see if it stops breaking), go through the .sln and proj files (wherever the framework version is specified, I don't have VS2010 here now to check) to see if there's any discrepancies (one file says 3.5 and another 4.0 or similar), create a new 3.5 project in VS2008, upgrade it to VS2010 and then change it to 4.0 and see what happens. I'm not sure if any of these suggestions will solve anything, but they might give you more information for finding the issue. – Hans Olsson Jan 24 '11 at 13:09
  • when i changed the project back to 3.5 Visual Studio working fine and I can edit during debugging, but this project requires some features from the .net 4.0 and for that we upgraded to Visual Studio 2010, so I've to solve this problem on the 2010 Version – Cracker Jan 24 '11 at 13:31
2

working with VS2017 community I had this aggravating problem: if you port an existing project the tag EmbedInteropTypes may not be in the .csproj file yet, a search is futile. If that's the case, add the tag at the end to the property group Debug|x86 (or whichever you use) to the .csproj with a text editor:

before:

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x86\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DocumentationFile>bin\Debug\MyProject.XML</DocumentationFile>
    <DebugType>full</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>

after:

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x86\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DocumentationFile>bin\Debug\MyProject.XML</DocumentationFile>
    <DebugType>full</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <Prefer32Bit>false</Prefer32Bit>
    <EmbedInteropTypes>false</EmbedInteropTypes>
  </PropertyGroup>

This must be done with all projects that belong to the solution!

Andy3D
  • 97
  • 6
1

In VS2013 I had to enable "Use Managed Compatibility Mode" in the debugging options. I think it is because I have a .Net 4 project referencing a .Net 2 assembly.

For another project in the same solution I had to uncheck "Define TRACE constant" in the project properties.

AndrewS
  • 3,450
  • 1
  • 21
  • 26
  • In my case, enabling "Managed Compatibility Mode" made my Edit-and-Continue feature stop working completely: even an attempt to edit was blocked with an "Edit and Continue is not supported in Managed Compatibility Mode" message. This was on VS Community 2017. – Sinus the Tentacular Jun 27 '18 at 22:25
1

In Visual Studio 2015, I've deleted the .vs folder (where the new style .suo file is), deleted all bin and obj, and also uninstalled Resharper 2015. Edit and Continue is back.

(side note: intellisense is now showing autocomplete almost instantly, whereas it was taking 2 to 5 seconds before, maybe resharper's fault, and maybe unrelated...)

Thierry_S
  • 1,526
  • 16
  • 25
1

For me this was caused by Nuget failing to download a package (built for Net Framework) to a Net Standard project that was being referenced. Nuget entered an infinite loop (look in the output window).

The solution was to turn off the 'automatic package restore' setting see: https://developercommunity.visualstudio.com/content/problem/26638/nuget-infinite-loop.html

to access this setting Tools > Options > NuGet Package Manager > General

Declan Taylor
  • 408
  • 6
  • 8
1

I had to uncheck "Enable Native Edit and Continue" in Tools -> Options -> Debugging -> General:

enter image description here

voxoid
  • 1,164
  • 1
  • 14
  • 31
0

Reading the above, my UI project has Shell32 with "Embed Interop Types" == true. I changed it to false, and "edit and continue" started working.

J Frisby
  • 29
  • 2
0

In the Solution Explorer view, right-click on each reference of References, choose Properties. In the Properties view, sign False to the field of Embed Interop Types. This worked for me.

CJBS
  • 15,147
  • 6
  • 86
  • 135
0

For who still gets this error even with Visual Studio 2017

No dynamic/Portable Class Libraries/Nuget packages or dependancy problems. No errors or warning highlighted by Visual Studio.

After hours spent trying all the solutions posted in this and other threads and webpages, the only solution that worked for me was to check-in, remove the Workspace and Map&Get again.

To remove the Workspace, Source controlAdvancedWorkspaceRemove.

I'm using Visual Studio 2017 Community up to date and after a relatively fresh install on a new machine (one week and few work hours).


Methods I've tested with no success prior to the solution above

  • Made sure Edit & Continue was enabled in Visual Studio options. Untick and tick it back again
  • Deleting bin and obj for all project in solution
  • Clean and Rebuild all, restart VS / reboot in combination to the above
  • Checking compile options and Nuget packages and dll compatibility for the projects, inspired by this
  • Unloading the projects in various combinations to test dependancy problems or other issues (inspired by this)
  • Deleting solution an re-downloading it (without removing the Workspace)
  • Sign False to Embed Interop Types
  • Set <_ResolveReferenceDependencies> to true as explained here
  • Combinations of the above with restart of VS and reboots

After this, I made a check-in and downloaded the Solution on another machine running the same version of Visual Studio (2017 Community). As I didn't get the Edit&Continue issue there, I went for the Workspace removal.

alelom
  • 2,130
  • 3
  • 26
  • 38
0

In my case, what worked was unchecking "Require source files to exactly match the original version" in Debugging options. VS Community 2017 here.

0

Removing the * from the assembly versions of my referenced projects solved the issue for me.

From Github:

"I reproduced this issue on a mix of VB and C# projects with [assembly: AssemblyVersion(1.2.3.*")]. Once a VB project references a C# project with this setting things start collapsing. It looks like it has the same problem the other way around." -rhuijben

https://github.com/dotnet/roslyn/issues/28224

(At risk of being flagged, seems we have been suffering from VS Edit and Continue issues for over a decade. It's shocking to me that the Microsoft Visual Studio team hasn't cared enough to help developers by providing more verbose info when this occurs)

yodag123
  • 141
  • 1
  • 6
0

I tried all the above, none worked. It was apparently due to enabling some low-level debugging options (view registers...)

Tools -> Import and Export Settings -> Reset All Settings

resolved it

smirkingman
  • 6,167
  • 4
  • 34
  • 47
0

What worked for me was similar but not exactly like the accepted answer. I had an anonymous type created as a result of a LINQ query; i.e.

var thingy = (from thing in things select new { thing.Property1, thing.Property2 }).First();

When I changed the anonymous type to a tuple, the problem went away:

var (thing1, thing2) = (from thing in things select (thing.Property1, thing.Property2)).First();
Eric Pohl
  • 2,324
  • 1
  • 21
  • 31
0

I figured out one of the reasons my project was not letting me continue and edit while in debug mode. You can not have two c# files with the same filename even though they are in different folders and different name spaces and might have different class names. I changed the class name and that still didn't fix it. You have to change the .cs filename.

.Net Framework 4.8 doesn't have this issue so .net core added this feature.

PHPGuru
  • 398
  • 3
  • 9
-1

In VS 2015 this error was caused by a nuGet package I had recently installed. By uninstalling this package and reinstalling, the bug was fixed.

Mike
  • 620
  • 7
  • 21