Updating Visual Studio leaves my app critically wounded - visual-studio

I updated the Visual Studio Developer tools and voila! Some of my code no longer functions. I can debug, but 90% of the fixes I had made in the past day disapears whenever I debug. It worked earlier today with the old Visual Studio; but now, the effects of the code simply don't show up when I debug.
I can see the code in the code-editing window, but it doesn't debug any way I try. Does anybody know how I can fix this?
P.S. If this belongs on SuperUser, I'll be happy to put it there. Simply tell me, and I'll move it.

Manually clean the solution and output folders (by deleting the obj and bin folders while Studio is closed). Re-open and rebuild. If it's in a referenced DLL, drop the reference in the consumer, build to get a failure, then re-add.

Related

Visual Studio sometimes not saving files

I am getting an inconsistent error with Visual Studio 2015 that is severely hampering my productivity.
I am working on a very large application that I have pulled down from TFS. Sometimes when working I will try and save the file that I was working on, and have the asterix not go away and the file not save. This is despite running the application in Administrator.
Sometimes the solution is simply to rebuild the project and then try to save, however when this doesn't work I need close down visual studio and start up again, losing all my saves anyways.
This isn't too bad when I am working on .net files because the problem happens a lot less, and the solution is almost always to just rebuild, which is much better than having to re boot vs. However recently I have been working on javascript files within visual studio, and with them I get about one save, then the problems comes up, and rebuilding doesn't fix issue, causing me to have to reboot visual studio every save I make...
I have tried searching online for people who have faced a similar issue, or asked around my work, and no one seems to have ever had a similar problem. So hopefully, for my sanity's sake, someone knows what the heck is going on with my visual studio. Thanks!
I am currently running VS2019 16.7.2 and sometimes it just refuses to save no matter what I do. I try Ctrl + S, File -> "Save all", closing the window (which causes the changes to be lost) but nothing works.
Though for some reason when first I press the File -> "Save ... as" option in the menu and then cancel it, that releases the "save lock" and suddenly I am able to save again. Not really a satisfactory solution but at least all changes aren't lost. Maybe it will work on other versions as well?
I will give an answer to a problem which might not be exactly the same as the one reported by the author, but it is fairly close, and people searching for a solution to this problem are likely to arrive to this question.
In my case, in my entire solution containing thousands of files, there was only one particular file that Visual Studio was consistently failing to save when needed. As a result, after each commit, the "Git Changes" tab would not appear completely empty. All files would be committed, except this one file, which would appear as still uncommitted. So, I would have to manually save it and then amend the last commit in order to arrive at a completely empty "Git Changes" tab.
I thought that the problem might be due to some discrepancy between the letter case of the filename on disk (which is what the "Git Changes" view reports) and the letter case of the filename in the visual studio project file (which is what the "Solution Explorer" view reports) but it turns out that this was not it.
After much troubleshooting, I discovered that the following sequence of magical incantations solves the problem, I have no idea why:
In "Solution Explorer" locate the problematic file.
Rename the problematic file to something else.
Commit (with amend if you wish) the file.
Rename the file back to its original name.
Commit (with amend) the file again.
Restart Visual Studio.
The last step of restarting Visual studio is not strictly speaking necessary, but it is useful in case you have a letter case mismatch, because Visual Studio seems to be somehow caching filenames, (or at any rate not detecting that the capitalization of a filename has changed,) and restarting it makes it come to its senses.
I realize this is an old question but I had a similar problem with a solution file I had upgraded from Visual Studio 2015 to Visual Studio 2022. I was unable to save any changes to the solution, although the file was writable in notepad.
Deleting the section in the solution file as suggested by Richard Stanton's workaround fixed it for me!
developercommunity.visualstudio.com Workaround
Delete the following section from the solution file:
ProjectSection(FolderStartupServices) = postProject
{B4F97281-0DBD-4835-9ED8-7DFB966E87FF} = {B4F97281-0DBD-4835-9ED8-7DFB966E87FF}
EndProjectSection

my project files are being closed upon closing visual studio

Weird thing. I'm working regularly with my Visual Studio. However, at some point in time, with a single project, when I close the Visual Studio, when I re-open it all the files are closed, i.e., I get everything as usual except that I need to re-open all the files that I worked on.
Does anyone know how to make Visual Studio keep my files open?
Have you tried resetting all your settings? Tools --> Import and Export Setting --> Select Reset all setting.
Otherwise, you might want to try a clean uninstall/reinstall. But I venture you might have tried that already, given you did your own research before asking your question.
Lastly, some weird behaviors I used to have in VS were sometimes fixed by a starting it as an admin, I never clearly understood why.

Visual Studio “Go to definition” disabled or gray out

Visual Studio's Go To Definition is disabled and F12 doesn't work. Other commands like Alt-F12 may continue working.
Close the solution.
Delete the intellisense database file for the solution: [solution].ncb or [solution].suo
Reopen the solution.
Optional: Rebuild the solution.
Note that this can also be as a result of disabling database for C++/C#.
In Tools - Options, type "IntelliSense" into the search box, and click on C/C++ - Advanced. In the Browsing/Navigation section, change Disable Database to False, if it is not so already.
After re-enabling, close and reopen to force rebuild.
NOTE: IntelliSense will produce large files on disk (*.sdf and ipch) that should be excluded from Git, for example.
I know the solution has been resolved. However, I encountered the exact same problem. I searched internet. None of the trick works including this one.
Eventually, I figured out. I right clicked on the file that had the problem. I included the file in the project. Isn't that obvious. Actually not, the file has been included for a week. I have been working on that file more than 7 hours a day for the whole week. Up till yesterday 6:20 pm.
Oh, I could not compile correctly this morning. There were tons of syntax error message yesterday. This morning, I was able to compile. Strange. right? Then my go to definition was gone.
Took me a while to find out cs and designer.cs were certainly excluded, but aspx file was.
I solved the problem. Did my figure slip? I don't know.
That is one thing people check. Either yourself, someone else, or system accidentally exclude the cs files without the knowledge. I know it is strange, but it solved the problem. There are weird scenarios in Visual studio. People can present 200 solutions. They work for 99% of time, but not our cases. I just bring one more scenario
I encountered this in Visual Studio 2010.
For me, this solution did the trick
Close all the files.
Reopen the files.
and you are good to go.
This also happens, if Visual Studio has files opened, which are not in the current Solution.
I don't know how I got to this state, where files of a different solution where open as I didn't open them manually, but a quick check of the file path showed that those weren't files of the opened solution.
Therefore, "Go to Definition" was disabled.
I found that I had to remove my TFS mapping:
VS 2010 > open Team Explorer > Drill into the team project > double click source control > right click on the team project in the left pane and do "Remove Mapping" > after everything was removed I manually went to the local folder and deleted any lingering files > back in source control explorer I re-mapped to the same local folder and re-pulled all the code. Now the "go to definition" works again.
Not sure why I had to do this...
Check dll in references which is yellow. Remove it and add again.
I've just had this happen with a CMake-based C++ project in Visual Studio 2019. Everything was fine yesterday, then when I opened it up today all the Go To Definition/Declaration etc options were greyed out everywhere in every file in the project, even for things defined within the same file (and the syntax highlighting didn't look right either). It did work if I opened one of the .cpp files separately on its own (without loading the Project/Solution).
I tried various things including the answers here and telling it to generate the CMake cache again, but what finally fixed it was actually deleting the CMake cache. The Delete Cache option didn't seem to work (all the files were still there on disk, and there was some sort of failure message in the Output window) so I just deleted the entire "out" directory from the project directory (well, moved it somewhere outside of the project, just in case). Loaded up Visual Studio again, it rebuilt the cache again automatically and IntelliSense immediately started working again! I just had to wait 5 minutes for it to compile everything again when I wanted to run the project.
Maybe it wasn't necessary to remove the entire "out" directory, but when I clicked "Open in Explorer" under the "CMake Cache" menu it opened the actual build directory (which was the only thing in the "out" directory anyway) so I assumed the entire thing was related to the cache and was getting too fed up with it to try to narrow it down further. It's probably only certain files within that directory really.
Tried all the above solutions in my VS2019, nothing worked for me. Than I've noticed an update sign on the bottom Right corner. After updating the VS all options were restored.
Simple just check your bottom left corner of Visual Studio if Restricted turn it as a trusted and your problem will solve.
In my case due to my project is mapped with TFS so I am unable to go to definition also my project files showing read only when opening from Solution. So I have move to my root folder mapped with TFS and then right-clicked on folder > Go to properties > Attributes section was Read-Only I have unchecked it and clicked Apply. Reopen visual studio. Everything is now working fine.
I faced the same Issue in my Visual Studio 2019 version.I followed the below Steps:
Go to references folder in the solution.
Click on Manage Nuget packages.
Click on Browse.
Search for 'Microsoft.Net.Compilers'.
Click on Update.
This Worked for me.
In my case, another Visual Stuidio was opened (not closed succsessfully). Close all examples of VS, then re open solution.
Just open the Solution using Windows Explorer, instead of opening it from inside VS...

Visual Studio project execution stopped shortly after starting

Yesterday I wanted to continue working on a project of mine, so I started Visual Studio and asked it to run the project to remind myself, what was already implemented and what wasn't.
The project got built and started, but seemed to quit right away. No error message, nothing.
No matter what I did, whether I rebuilt the project or cleaned it, nothing changed.
This didn't make sense, since the last time I tested the project, it worked perfectly (and I didn't modify anything in the code since then)
So, I assumed I had a hidden bug somewhere in the code, that just didn't show up previously.
I put a Breakpoint somewhere near the beginning of the code, and ran the project.
As expected, Visual Studio paused the execution at the Breakpoint and highlighted it.
I decided to set another Breakpoint somewhere later in the code and continue execution, but before I could even move my mouse, the project stopped.
Restarting Visual Studio didn't help, but restarting the PC did. Therefore, I'm assuming that something on my system was terminating my project, shortly after execution begun.
Now my question is: What exactly happened, and especially: why did it happen?
The problem came back while I was writing this question. I don't feel like restarting my PC every couple of hours...
I really appreciate the time you took reading this and I look forward to your answers.
I'm aware that I'm answering my own question, but since I've solved it myself, I thought others might want to know how I did it (for the sake of future generations)
The thing is: I've recently added Visual C++ to Visual C# before Visual C# started having problems.
So I deduced, that maybe the installer for Visual Studio messed up with something and decided to reinstall Visual Studio.
Problem solved.
So: if your projects stop without warning even while paused on a Breakpoint and you've changed something in your Visual Studio installation (like added Visual C++ in my case), you might need to reinstall the whole thing.
Luckily, the Visual Studio installer offers a "Reinstall" option, so you don't need to uninstall and reinstall manually.
I found about this solution, after talking to a more experienced colleague. I just wish I asked him first. Still appreciate your efforts in the matter, though.
EDIT:
I recently noticed a similar bug acting up for C++ programs this time, where the window border would be outlined in red. The thing is: it's not Visual Studio's fault, but in fact Avast Antivirus' fault. More specifically, its Sandbox mode.
So, if for any reason, you notice programs quitting without crashing, shortly after starting and their window border having a red outline, you're very likely using Avast Antivirus and should deactivate the Sandbox mode.
Happens to me from time to time.
Sometimes closing and opening VS helps, sometimes you have to restart the computer.
I assume it must be related to some DLL or something that is loaded into memory and corrupt, or something like VS loosing the reference to it, and not unloading it correctly/replacing it.
I also once had this strange bug, where I started VS, just like any other day, and my project crashes instantly with some H_RESULT error (some DLL related Error) upon run. After having spent around 1hour searching for the source of the problem, I went into the reference section, and what did I see there : the worst possible circular reference ever : my business project had a reference to ... itself ! The kind of stuff you could not do if you wanted to.
The weirdest part of this, must of been that VS managed to compile the project, and it only crashed while trying to run it ...

Visual Studio 2010 holding onto file handle

I'm experiencing something very unusual in my VS2010 today which it hasn't done in the past.
I have a solution with 8 projects inside. One of them is a central DLL project which contains the bulk of the code.
When I open VS and open the solution, I can press F6 to build and everything happens as expected. If I comment a line out or something and press F6 again to build, there is an error. It can't copy the DLL from the obj\Debug folder to the main output folder because it is in use by another process. If I close the IDE and restart it, I can rebuild the solution with no problems, but only once. Closing the solution and re-opening it (without restarting the whole IDE) doesn't help.
When I search for the handle to the DLL in Process Explorer, it is VS2010 itself!
Basically, I have to restart my whole IDE every time I want to build my solution, which is obviously completely impractical.
VS2010 has never done this with me before. Any ideas on what it might be and what I can try?
Happened once to me, I solved it by deleting all the references to that particular project then re-adding them. YMMV.

Resources