Вопрос

I was working on a class in visual studio 2010 when suddenly my computer crashes. after I restart the computer. I start Visual studio and I find that class to be completely empty. it contained more than 1000 lines of codes before the class. is there anyway i can recover that file?

Help please because I don't have another copy of it (Stupid of me)

Это было полезно?

Решение

If you cannot find the source code file, try using Reflector to decompile the most recently built dll you have containing that class. It won't give you your complete source, but at least will give you something to start with.

Note: Reflector is no longer free; if that matters, try dotPeek from JetBrains instead.

Also, look into using a source code control system. This will let you 'commit' versions of your code to a repository, so you'll have a copy in case something like this happens in the future.

Subversion, Git, and Mercurial are popular ones; In my opinion, Subversion would be the easiest to start out with, especially with TortoiseSVN (OS integration) and AnkhSVN (Visual Studio integration). If you don't want to worry about setting up a repository/server, look into a hosted solution, like Beanstalk, which offers Subversion and Git and lets you try it out with a free, limited account.

Good luck - I hope you are able to recover your source!

Другие советы

Something which worked for me was back-up. BTW I was trying to recover a VS2013 file on a Windows 8 machine.

Try to check in below location in your system.

C:\Users\username\My Documents\Visual Studio \Backup Files\ProjectFolder

I found an original file with original-date.filename.cs name and a recovered-date.filename.cs files.

The original was the one needed. Deleted the one in project, added the original file and renamed it to file.cs. Tried building and debugging and it gave the expected results.

Also just want to add one more thing... In my case i had an aspx page with its respective .cs and designer.cs The .cs file got corrupted and I did build on project, with the designer.cs the project got build successfully and the dll got replaced. And when i tried to recover using reflector everything was in a state no return. :(

So don't build the project if you see any file got corrupted.

This happened to me a few times as well when Visual Studio was crashed or System was shutdown unexpectedly.You can recover these corrupted file using Recuva. It dose not recover the file every time but in most of the cases it's work perfectly.

Below are the settings which you need to configure before recovery.

  1. Start Recuva. Enter Advanced mode if the Wizard launches.
  2. Click Options.
  3. In the Options dialog box, click the Actions tab.
  4. Click Scan for non-deleted files, and then click OK.
  5. Run the Recuva scan as normal. Non-deleted files are indicated with a green double-circle status icon.

Hopefully, you will find your corrupted file in recovered files as it recover multiple versions for that file.

in visual studio 2019 I find the file in a files with TMP extension

FileName.cs~xxxxxxxx.TMP

Very useful question. I got issue of file crash on sudden shutdown of my PC. recovered file using "Recuva"(download link: https://filehippo.com/download_recuva/) software. Scan for non-deleted files was helpful.

I got help from: https://www.samnoble.co.uk/2014/11/30/visual-studio-crashes-and-a-corrupted-cs-file/

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top