I´d like to know if there is any way to edit the codebehind of an Asp.net web application while debugging?
When I try this, a message is displayed on the status bar saying "cannot currently modify this text in the editor. It is read-only".
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.
Related
.NET/MVC3 newbie, so please bear with me!
I've searched for this answer all over but cant find exactly what im looking for, so here it comes...
Lets say that i'm developing an MVC3 app with Visual Web Developer Express and i go about deploying the site using the built in publishing tool.
But now that my site is up and running i find that i need to make a minor adjustment in one of the views. I update the view and save the file, and use my FTP program to upload the new file.
The problem is that MVC3/.NET doesn't seem to refresh/change the view, because it's still using the old version.
Of course I have tried refreshing (in many different browsers even), but it still won't load the new view.
Is this normal behaviour, meaning that i have to publish every time i make some minor adjustments (kinda time consuming)? I really can't imagine that this is the case, so i'm wondering if you could shed some light over this?
Appreciate any replies!
/Mikael
If you upload the view (.cshtml) file and that is the ONLY part of the application that has changed, a refresh will reflect the change - you may have to ctrl+f5 to clear the temp cache. However! If you change ANY of the controller code or action code, or any c# (or vb if thats what you use), then you MUST re-upload the compiled .dll associated with the entire application in order for the changes to be reflected.
Our application registers events OnInit. When developers create a new aspx file from the visual studio template, it has AutoEventWireup="true". This leads to event handlers being registered twice and run twice.
Is there an easy way to cause the compile, build or other post build step to fail when the directives are set "wrong".
I'm using Visual Studio 2010 and TeamCity. I'm open to running any technology as a postbuild step.
You could precompile your site. Precompiling involves compiling the aspx and ascx files aswell as the .cs. It will make your site faster and it ensures things hook up a bit better, the downside is you cant change the aspx or ascx after you have compiled them.
http://www.dotnetperls.com/precompiled
This SO page describes a couple of ways of doing it
Compile Views in ASP.NET MVC
You could try integrating StyleCop with TeamCity, and create a custom StyleCop rule that checks for this. Not sure how difficult it would be, but it's what comes to mind. See this question about using StyleCop with TeamCity.
Also, as suggested by Erix, update your templates to prevent this from being the default behavior.
I have been working on a MVC 3 application on my laptop, which now has crashed. I have uploaded the newest edition of the site through the "Publish" method in VS2010. Is it possible to retrive the source code of the application? Because i cant see the Models or Controllers on the FTP.
Thanks
I have used a decompiler before to get back source code from a compiled website.
It doesnt give you the files all nicely ready to start developing again, it is a bit pain staking going through the decompiler and getting all the code you need out. But it can be done.
I cant remember which one i used, im sure a quick google will give you loads to choose from. I think there might even be one shipped with vs.
Hey guys,
i have a website, i want to place the compile code on the production server, now i took the code on the local machine and trying to compile source code on local machine, but whenever i compile the code, in one of my control(ascx.cs) file i am getting error that the control does not exists in current context, i checked everything, Inherits, CodeFile, even in the code behind(.cs) file, everything is perfect, even i get the control id in the intellisense, when i remove the control and again add the same using intellisense, the errors gets removed but after i publish site, the same error comes again....
Please reply with some suggestion/solutions.
I've had this issue before when referencing another project. It would give it intellisense, but then trying to compile would cause errors and take away intellisense. Removing and re-adding it would give me intellisense back.
The problem ended up being the target framework. The project was referencing .NET 4 Client Profile, whereas the project it was referencing was just .NET 4. Apparently this difference is subtle enough to trip up visual studio in the confusing way described above.
So take a look at your project's target framework, maybe you'll get lucky.
Definitely check your Inherits or CodeFile. I've had this happen before where I had them pointing at the wrong files.
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?
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.
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.
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.
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.
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
For the record, I had a similar problem with VS 2008 and a different solution resolved the problem for me. Editing code in Visual Studio 2008 in debug mode
Check that you are not in release mode.
In release mode you cannot edit your code while debugging. Just change mode to Debug