views:

2987

answers:

8

I have VS2005 and I am currently trying to debug an ASP.net web application. I want to change some code around in the code behind file, but every time I stop at a break point and try to edit something I get the following error message: "Changes are not allowed when the debugger has been attached to an already running process or the code being debugged is optimized."

I'm pretty sure I have all the "Edit and Continue" options enabled. Any suggestions?

+1  A: 

The application is actually running off of a compiled version of your code. If you modify it it will have to recompile it in order for your changes to work, which means that it will need to swap out the running version for the new compiled version. This is a pretty hard problem - which is why I think Microsoft has made it impossible to do. It's more to protect you from THINKING some changes were made when they really weren't.

+1  A: 

You are allowed to make changes to the *.aspx file while it runs, and you can hit refresh on your web instance to see those changes immediately. However, you cannot make changes to the *.cs/*.vb or *.designer.cs/*.designer.vb files while the program runs.

Jarrett Meyer
+6  A: 

This may seem counter-intuitive, but turn edit and continue off.

There might be another "allow me to edit read-only files" or "allow me to edit even when I am debugging...no really!" setting somewhere, but I don't have 2005 to look at to check.

In 2008, turn off edit and continue and you can edit while it's running (but those changes aren't appplied.)

If you actually want to use edit and continue, you also have to enable it for the project, on the web tab of the project settings.

Chris Bilson
+2  A: 

For Asp.net it is possible to think of two types of 'edit and continue'.

One is a classic edit and refresh the browser. This works because the browser refresh recompiles everything except precompiled code behind files. This is not referred to as Edit and Continue, though in practice it provides a similar effect. In this mode you cannot change code behind files, because they were precompiled and deployed, but you can change just about anything else.

Another mode allows you to change precompiled code behind files but nothing else ... (this is the mode Chris Bilson mentions which needs to be set on the project properties for ASP.Net). In this case you are using the Edit and Continue feature of the debugger, which knows preciously little about ASP.net. The debugger just sees a loaded .Net assembly and can modify it when stopped in the debugger because there is a project in the solution that claims to know how to build it. In this case you are prevented from modifying things that would otherwise mess up the debugging session. This method however is the only way to change the code while it is running rather than requiring a browser refresh.

Steve Steiner
Thats great, setting the Enable and Continue on web project tab solved my problem.
Greg
A: 

Check that you are not in release mode. In release mode you cannot edit your code while debugging. Just change mode to Debug

abc
+1  A: 

I search for this on Visual Studio 2008 WAP (Web Application Project) and it took me two days to find the solution, so here it is in the hopes it helps somebody else:

There are two locations that have to be checked, one it under tools-options-debugging-Edit And Continue-Enable Edit And Continue, the other is right click project-properties-Web-Enable Edit And Continue

Rob
Thanks Rob. I always forget about this second place.
dustinson
A: 

I struggled with this for ages until I finally realised that user abc is correct, the simple option worked for me, I had the mode set to release

Marbella Consulting
A: 

For the record, I had a similar problem with VS 2008 and a different solution resolved the problem for me. http://stackoverflow.com/questions/2781060/editing-code-in-visual-studio-2008-in-debug-mode

user279521