Can't edit code in visual studio 2013 while running - vb.net

I'm developing a web site in VS2013 Update 2 with .net 2.0 using IIS as web server. My problem is that when I run the web site, i can't edit it. Not trying to edit and continue nor edit while debbuging. I'm saying that once the page is completed loaded on web browser, i cant change anything on source files(.vb) until i stop and run the project again.
Something strange is that i formated my pc recently and after i reinstalled everything it was working. Then, VS chrashed and on the next start the problem appeared.

that is normal. you cannot edit .vb or files that get compiled when it is running. You can however edit the html, javascript, css files even when it is running since those files are not compiled.

To enable edit and continue in vs2013, you need to check edit and continue in mvc project property > Web (scroll until reach end of options) and disable or uncheck edit and continue in Tools > Option > Debugging > edit and continue > uncheck.
Then build the application and run the project.
This should now work when you change the controller (tested)

Open your project using option 'Open->Web Site' then you will able to edit your code while vs2013 is running.
Do not open solution file because it is not allow this option

Related

Razor Runtime Compilation breaks Hot Reload and therefore debugging in ASP.NET

Nomenclature
This question is about three related subjects that allow the developer to introduce code changes in a running application without having to rebuild and restart said application:
Edit and Continue: Visual Studio's functionality to modify assemblies that are being debugged. You can edit managed code while on a breakpoint (within some constraints), and it'll magically be applied to the debuggee.
Hot Reload: introduced with Visual Studio 2022, kind of like Edit and Continue, enabling runtime recompilation of managed code without having to be paused on a breakpoint or even having a debugger running to begin with.
Razor Runtime Compilation: editing Razor views of a running application, by recompiling them on save of a .cshtml file.
Setup
Visual Studio 2022 (17.4.4)
.NET 7 (SDK: 7.0.102) or 6 (SDK: 6.0.403)
NuGet: Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
The problems described below also occur on combinations of earlier versions of those components. Then:
Start Visual Studio 2022
Create an ASP.NET Core Web App running on .NET 6 or 7
Add the NuGet package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
Change the generated Program.cs code to the following to add Razor Runtime Compilation:
// Add services to the container.
var mvcBuilder = builder.Services.AddRazorPages();
#if DEBUG
mvcBuilder.AddRazorRuntimeCompilation();
#endif
Reproduction
Now set a breakpoint in any view, Index.cshtml would be fine, and run the application.
As soon as the breakpoint is hit, change some Razor code. Or don't, the issues trigger from just having (multiple?) .cshtml files open as well.
Then hit Ctrl+S and F5 to apply your changes and continue running your application, and tada.wav:
Hot Reload can't automatically apply your changes. The app needs to be rebuilt to apply updates.
Alternatively, change some code in the code behind (.cshtml.cs). Now you will get random NullReferenceExceptions or ExecutionEngineExceptions when continuing.
Workaround
Close all .cshtml files before starting a debug session.
Questions
Is it possible to:
Get some confirmation that I'm not the only one that encounters this?
Have "Edit and Continue" without "Hot reload"? The settings for those seem to have been combined, it's either all or nothing.
Make this (editing Razor files and C# code while debugging) work without getting these dreaded errors?
How can I get Microsoft to set the Cancel key (Esc) to the Continue Editing button?
It would appear that not having Razor Runtime Compilation (Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation) installed in the affected project largely mitigates this error (though the runtime still throws the occasional NullReferenceException/ExecutionEngineException while trying to reproduce the issue do my work).
As Hot Reload will also recompile your Razor views, simply uninstall the RuntimeCompilation package and you should get fewer errors.
Edit: this is not entirely true, the error popup still gets shown, albeit less frequently.
Things to try when Hot Reload won't work:
1.) Check the 'Hot Reload' output window and Error List for clues to why hot reload failed. For instance I found an error about having a 'COR_ENABLE_PROFILING' environment variable in the error list after getting the usual dialog. This appeared in the VS2022 17.5 Preview 6.0 and I'm not sure if it was there before.
2.) Make sure COR_ENABLE_PROFILING is disabled in your environment variables.
3.) Search the entire project for RuntimeCompilation (could appear in web.config, launch properties, packages) and remove them.
4.) Disable 'Native Code' debugging in your debugging profile.
5.) Restart your PC and check again

VB.Net build error targetting .Net 2 in VS2013 [duplicate]

My app keeps getting this error (I'm using VS 2013, VB.NET, and Windows 8.1, by the way):
Could not run the "GenerateResource" task because MSBuild could not create or connect to a task host with runtime "CLR2" and architecture "x86". Please ensure that (1) the requested runtime and/or architecture are available on the machine, and (2) that the required executable "C:\Program Files (x86)\MSBuild\12.0\bin\MSBuildTaskHost.exe" exists and can be run.
The app is for .NET 3.5 (3.5 and lower versions get me this error).
I try to run the app again. Sometimes, it works; sometimes, the error comes back.
I already tried looking up for answers at Google and the answer they gave me turned out to be: "Your build's username is too long" (they said that 20 characters or more cause the error), but it's not true. My user name is 5 characters only. Anyway, I don't think my build's username's length has anything to do with it; it makes no sense.
Does anyone know what is wrong with 3.5 and lower versions? Thank you.
This fixed the issue on my machine:
To resolve it, go to your csproj file and add the following line under the default property group:
<PropertyGroup>
...
<DisableOutOfProcTaskHost>true</DisableOutOfProcTaskHost>
</PropertyGroup>
Found here.
Clean and rebuild solution worked for me.
Adding this in each project is a cumbersome task. So you can set it in the environment variables.
Click Start>> Right-click Computer >> Properties >> Advanced system settings >> Click Environment Variables button to open the dialog, then under the System variables section, click New… button, type the Variable name = DISABLEOUTOFPROCTASKHOST, and type the Variable value = 1, then click Ok.
More here
I'm using VS 2013, VB.NET, and Windows 10, 64 bits, by the way
Just change in XML properites , Services : .NET Framework 4.6 instead .Net Framework 2.0 (Default)
and working fine for me.
I try adding the follow but didn't works
<PropertyGroup>
...
<DisableOutOfProcTaskHost>true</DisableOutOfProcTaskHost>
</PropertyGroup>
this solve this issue for me, adding the same as enviroment Variable
DisableOutOfProcTaskHost=true
I encountered this error when trying to build a sample solution that was included in some software that was installed under C:\Program Files\. Visual Studio prompted me to restart with elevated privileges (as it does when opening a solution in a "secure" location), however the build failed with the OP's error message.
Copying the solution to a "normal" folder (e.g. C:\Temp) solved it for me.
I tried opening an old VS2010 vb project inside VS2013 recently and just ran into this problem. I got around it this way:
I went to the vb project's properties page
I clicked the "Debug" tab
In the "Enable Debugers" section, I saw that the "(x) Enable the Visual Studio hosting process" checkbox was already checked.
I tried un-checking the "( ) Enable the Visual Studio hosting process" option
I saved these changes (Ctrl+S)
I then checked the "(x) Enable the Visual Studio hosting process" checkbox once more
I saved these changes (Ctrl+S)
My next re-build of the project was then successful.
Luckily, I was able to observe how the .vbproj file changed in my version control, and saw that it added the following line into it (which was not there before, despite the checkbox already being set initially):
<UseVSHostingProcess>true</UseVSHostingProcess>
None of the answers in this worked for me. I had to run Visual Studio as admin. Hope this helps someone in the future!
If you don't know how to run a program as admin on Windows, click this link.

"GenerateResource" task CLR2 runtime error

My app keeps getting this error (I'm using VS 2013, VB.NET, and Windows 8.1, by the way):
Could not run the "GenerateResource" task because MSBuild could not create or connect to a task host with runtime "CLR2" and architecture "x86". Please ensure that (1) the requested runtime and/or architecture are available on the machine, and (2) that the required executable "C:\Program Files (x86)\MSBuild\12.0\bin\MSBuildTaskHost.exe" exists and can be run.
The app is for .NET 3.5 (3.5 and lower versions get me this error).
I try to run the app again. Sometimes, it works; sometimes, the error comes back.
I already tried looking up for answers at Google and the answer they gave me turned out to be: "Your build's username is too long" (they said that 20 characters or more cause the error), but it's not true. My user name is 5 characters only. Anyway, I don't think my build's username's length has anything to do with it; it makes no sense.
Does anyone know what is wrong with 3.5 and lower versions? Thank you.
This fixed the issue on my machine:
To resolve it, go to your csproj file and add the following line under the default property group:
<PropertyGroup>
...
<DisableOutOfProcTaskHost>true</DisableOutOfProcTaskHost>
</PropertyGroup>
Found here.
Clean and rebuild solution worked for me.
Adding this in each project is a cumbersome task. So you can set it in the environment variables.
Click Start>> Right-click Computer >> Properties >> Advanced system settings >> Click Environment Variables button to open the dialog, then under the System variables section, click New… button, type the Variable name = DISABLEOUTOFPROCTASKHOST, and type the Variable value = 1, then click Ok.
More here
I'm using VS 2013, VB.NET, and Windows 10, 64 bits, by the way
Just change in XML properites , Services : .NET Framework 4.6 instead .Net Framework 2.0 (Default)
and working fine for me.
I try adding the follow but didn't works
<PropertyGroup>
...
<DisableOutOfProcTaskHost>true</DisableOutOfProcTaskHost>
</PropertyGroup>
this solve this issue for me, adding the same as enviroment Variable
DisableOutOfProcTaskHost=true
I encountered this error when trying to build a sample solution that was included in some software that was installed under C:\Program Files\. Visual Studio prompted me to restart with elevated privileges (as it does when opening a solution in a "secure" location), however the build failed with the OP's error message.
Copying the solution to a "normal" folder (e.g. C:\Temp) solved it for me.
I tried opening an old VS2010 vb project inside VS2013 recently and just ran into this problem. I got around it this way:
I went to the vb project's properties page
I clicked the "Debug" tab
In the "Enable Debugers" section, I saw that the "(x) Enable the Visual Studio hosting process" checkbox was already checked.
I tried un-checking the "( ) Enable the Visual Studio hosting process" option
I saved these changes (Ctrl+S)
I then checked the "(x) Enable the Visual Studio hosting process" checkbox once more
I saved these changes (Ctrl+S)
My next re-build of the project was then successful.
Luckily, I was able to observe how the .vbproj file changed in my version control, and saw that it added the following line into it (which was not there before, despite the checkbox already being set initially):
<UseVSHostingProcess>true</UseVSHostingProcess>
None of the answers in this worked for me. I had to run Visual Studio as admin. Hope this helps someone in the future!
If you don't know how to run a program as admin on Windows, click this link.

WebMatrix 3 intellisense and publishing

Does WebMatrix 3 support intellisense for css libs you add or a customer css file you create? For me this doesn't work. It would be nice to have intellisense when using say twitter bootstrap for instance.
I cannot figure out why when I publish sometimes it selects only the files I've changed but most of the time it seems to publish everything. Why does this happen?
Thanks
I had problems with publish too so I don't recommend using the publish feature in Webmatrix. I recommend that you copy it directly like this; Right click the app directory in IIS and select "Remove" then just copy and paste the entire project directory from your local machine up to the IIS inetpub/wwroot directory. Then from within IIS7 right click that directory and select "Convert to Application". Works every time.

Why is my module not in the modules list?

I have a WCF service that I can debug. I put a breakpoint in the code at the point at which I want to debug and get the message
The breakpoint will not currently be hit. The source code is different from the original version.
I have been struggling with this for 3 days now and have tried everything I have found in other posts.
One thing that I notice is that if I go to Debug -> Windows -> Modules the module that I want to debug is not in that list. I think this may have something to do with it. Does anyone know what I should do.
Thanks,
Sachin
EDIT:
I have tried all these things and many more, but for some reason I still have the same problem. Is there any solution to this at all?
Try closing down visual studio after closing any files open in it. Then go into your bin folder for debug and delete all .pdb files. Now reopen visual studio and rebuild your project or do a clean and build ensuring you are in debug mode and not release mode. This issue can arise if your pdb files become locked. If you have a pdb file present for that dll then it should pick up that module for debugging.
If that doesnt work have you restarted your machine? If not try a reboot as sometimes the process can get caught up in Windows, and restarting will release the lock to overwrite the files.
Quick question. Is the module in question an external module or is it part of your current solution that you are debugging? If it is an internal module then the solutions above should definetly work as you will generate a new .pdb file for that assembly.
To state the obvious, this error means that compiled service does not match the source code i.e. source code has changed since service run. Make sure you rebuild your solution.
What I do to debug WCF services is to have 2 instances of Visual Studio. One runs a WCF service hosting app (console) and the other runs a client. Make sure you are running debug version. It should work (and debug) fine as long as the client can successfully connect to your service.
You get
The breakpoint will not currently be hit.
when a module with that breakpoint has not been loaded (yet). Your service will not be loaded until a client connects.
Right click on the project inside the solution explorer and choose to Clean. Build a new version of the project and the breakpoint will work again. If this not work, try to delete everything from the bin and obj folders, and build again your project.