Project file getting cleared when adding new file VS 2017 - visual-studio

I'm running Visual Studio 2017 on Windows 11 Pro. I have a large-ish Winforms project. Recently I started having trouble adding new files to the project.
I'll try to add a new class by right-clicking in Solution Explorer. The Add New Item form pops up, I'll enter the class name, click Add and I'll get an error pop up that just says
"The system cannot find message text for message number 0x%1 in the message file for %2."
The new file does not get added. I close the Add New Item form. Now my Project file is empty. Something happened during the error to delete the contents of my project file. I'm using Git and my client shows that everything was deleted so I just undo the changes in the project file so I haven't lost anything yet.
I'll try again and usually I can add a file. Then at some point I'll go through this again. I've rebooted my machine many times.
Anyone have any ideas what is happening?

The same error message also frequently appears in my VS 2019. Generally it happened during check in dan publishing proess. The workaround I did was to restart the application (VS 2019), and magicaly it solved my problem. But it doesn't prevent the issue not to happen again in the future.

Related

VS 2019 periodically can't save csproj files when I make a change to the files in my solution

I have a relatively new installation of VS 2019, running on a relatively new PC with Windows 11 (all about 2 months old). I also have Resharper and Web Compliler installed. All are up to date.
Within the last two weeks VS has begun having intermittent problems saving the csproj files when I add a new file to the project, or rename an existing file. It opens a file save dialog prompting me to save the csproj file, but when I click save, it then presents an alert dialog stating:
An error occurred saving the project file X.csproj
Clicking OK then returns me to the file save dialog. If I continue to click Save and then OK the alert, after a few tries, it usually saves eventually. Though sometimes it goes on so long that I abandon it.
Sometimes I can add/rename a file and it doesn't exhibit this problem at all.
I've noticed that when it's prompting me to save the csproj file, the existing file doesn't actually exist, so it doesn't appear to be a permissions issue, as the original file has seemingly disapppeared.
In addition to this, sometimes, if I try to duplicate a file in the project by clicking the file in the Solution Explorer, then hitting Ctrl+C then Ctrl+V, it gives me an empty error dialog (no error text), and the file doesn't duplicate. Again, persisting usually works eventually.
I've tried this on multiple Solutions, and I've tried suspending Resharper, but the problem remains.
I've tried repairing the VS installation, but that didn't work either.

Get Latest will give an error if file is Not downloaded

When Source Control Explorer shows that a file is Not Downloaded, selecting Get Latest Version will result in the following:
I don't remember this happening in the past. Is there a way to prevent this?
This kind of error or situation may occur when using "Get Latest Version" after someone else has just added a new item to source control.
For example, it seems to be triggered by multiple people working on the same solution at the same time. So if you check stuff in, then the other user gets this message when doing a "Get Latest". It appears Visual studio is detecting the files that were checked in by the other user and then pulling them in the background but not updating the local workspace data, so when you do a Get Latest, the files already exist, but it gets confused as to the source control status and throw this because it's confused.
One solution for this issue is closing your Visual Studio and clear TFS cache. Then open the Visual Studio and get latest for this file again.
Another way is directly removing the work space and create a new one then tfs will prompt you to download everything again. https://msdn.microsoft.com/en-us/library/ms181386(v=vs.100).aspx This should do the trick.

Inconsistent length calculation in projection snapshot

In Visual Studio 2017 something unexpected happened when I was working. I was editing razor view (nothing special, just normal editing - I've copy pasted small chunk of text) and all the sudden I've got this message:
I've tried to restart visual studio, delete suo file, delete my temporary folder... now I can not work inside this particular view. If I try to change anything in this .cshtml I got message above or this message:
What is this? I don't recall seeing this in previous versions of visual studio. How to avoid this and proceed with work?
I got this in VS 2019 and just needed to restart VS.
I found an issue and they claim the issue was fixed in the new version. So I updated, but the issue still occurred, maybe because it was triggered in the old version.
Clean/rebuild didn't work. What I ended up doing after updating (I don't know if all steps are necessary, but this worked for me):
Copy the contents of the old file (make edits if necessary, I didn't
have valid .cshtml at the time and I didn't want to run into the same error again)
Created a new file and paste the contents in there
Delete the old file
Commit code
Rename old file to new name
Commit code again
Then it was solved
I too ran in to this today with Visual Studio 2019. The editor was showing a bunch of what looked like metadata inserted in the middle of the file. The garbage text even ended up getting checked in to my repo when I didn't notice it.
Any attempt to "fix" (i.e. delete) the garbage data would result in the OP's errors or other strange errors. Closing VS and reloading didn't help.
What finally did work though was to copy the file contents (which oddly enough didn't include the garbage data when copied to the clipboard from VS) to a new file in Notepad++, then close VS, save the file from Notepad++ over the top of the original file, then reload the project. After that everything was fine.
It seems like something goes haywire and it gets it's buffers crossed or something. Once it happens, VS is unable to deal with the file any more and the only alternative seems to be editing it outside of VS.

Error message and empty list of build definitions in VS2012 after adding favorites

We have a bunch of build definitions available through TFS, and these were visible under Team Explorer - Builds in VS until a few minutes ago, when I tried to add a couple of them to "Favourites".
All I did was right click a build definition, and select "Add to favorites", then repeat the process for another build definition:
The result however, is a now empty list of build definitions - I can't seem to find any of them again. Furthermore, I get the following error message:
An item with the same key has already been added.
Any ideas how to fix this? Anyone know where the list of "favorites" is stored? (My reasoning is that if I can find and empty that list, then perhaps this issue would disapear?)
I ran into the same issue today. I was able to resolve it with the following steps.
Close Visual Studio
Open C:\Users[username]\AppData\Local\Microsoft\Team Foundation\4.0\FavoritesStore
Move the xml file from that folder to some other location
Start Visual Studio, open team explorer and navigate to Builds
At this point, the Builds pane opened without the error and "My Favorite Build Definitions" was empty
Moved the xml file back to its original location
Refresh the builds pane.
After refreshing, my favorite build definitions were back!
You may try (this helped to me with the same issue) to delete all the files in the following folder and restart VS2012 (Source):
C:\Users[USERNAME]\AppData\Local\Microsoft\Team Foundation\4.0\Cache
This issue occurred for me today when I had a mystery dialog open and it was blocking user input. I could not locate it or bring focus to it. I had to force a shutdown of VS, and after restarting my favorites were corrupt.
I found you can delete the cache for the favorites directly and restart the IDE. As soon as it launches you will see that VS will recreate the folder, and as soon as you add your first favorite a new favorites file will be created at that location.
C:\Users\\AppData\Local\Microsoft\Team Foundation\4.0\FavoritesStore
Writing an application or clearing the adjacent Cache folder are not necessary.
Favourites are stored in metadata on the user or group. You'll need to write an app to clear them.
http://geekswithblogs.net/TarunArora/archive/2012/10/18/tfs-api-add-favorites-programmatically.aspx

visual studio keeps asking to save project file as

I am using VS 2010 and recently I moved some files around and changed paths etc.
The solution still compiles correctly and all files are able to be loaded/compiled without error however just about every time I go to compile after a change it gives me the save as dialog and asks me to save one of the projects, if I try to give it a new name or something the dialog does not exist nothing I do can make it exit apart from pressing cancel.
If I do a build straight after cancelling it works fine and I'm not presented with the save as dialog. I have verified that the project file is not read only.
Any ideas as to whats going on here.
The solution is stored in TFS 2008
You need to do 2 things
1- remove the read-only tick from the project folder
2- when a save-as window prompts at build, just overwrite the project
next time you build, the window won't pop up
You need to run VS as administrator. (right click on VS Icon- Run as administrator)
I solved the issue. When I try to save as this time it gives the error that file is being used by another process. Google Sync prevents to save so it opens save as dialog.
You should put your project under a folder not sync while working.
Are the bindings in TFS set up correctly with the new location? TFS will mark files as read only unless they get checked in. It might have been marked as such before you moved everything around, and now, isn't being checked out properly.
Also, try closing sync. files tools like google backup and sync.

Resources