after a system crash down, one of my .cs file get lost.
The size of the file is 18KB,
when I tried to open it in VS2010, vs2010 auto opens it in NotePad, but the content is empty.
I tried to open it in NotePad++, the content turns into bunches of black block with word "NULL" in it.
I tried to "save as" in UTF8, but the file is empty as same.

How to recover this lost .cs file? :(

  • Have you run a CHKDSK /F on the drive (will require a reboot if your data is on the system drive)? If that doesn't help, then the data is probably lost - you're using a VCS, are you? ;) – Lucero Jun 24 '12 at 9:42
  • 2
    stackoverflow.com/questions/7622901/… – Usher Jun 24 '12 at 9:44
  • do you have your program exe file?.NET Reflector v6 provides support for .NET Framework 4.0 assemblies. Download it – irsog Jun 24 '12 at 9:47
  • @Usher great idea with Reflector. But it is payment tool now so I recommend to use ILSpy - wiki.sharpdevelop.net/ILSpy.ashx – RredCat Jun 24 '12 at 9:47
  • 4
    Visual Studio does retain some autorecover information. It's usually in C:\Users\USERNAME\Documents\Visual Studio 2010\Backup Files. – ta.speot.is Jun 24 '12 at 9:58

Try to use any recovery tool (isn't important that it is cs file).

and you have to use external subversion control next time.

I've been using xp-dev.com. It has free plan. Try to google and you will find out more services like this.

EDIT: There mentioned about code decompile - it is good idea. Try to use ILSpy - open source tool.


Did you ever compile it so you have a .dll/.exe file with the compiled class in it? If so, then you can use a decompiler such as dotPeek from JetBrains, or Reflector from RedGate to decompile the file and get the .cs code back.

You will be suprised how well preserved the source code is. Sometimes I find that the compiled->decompiled code is better looking than the code was before compilation...

Remember to use version control and backups, it does seem like there is something wrong with your disk.

  • Code compile/decompile as a Tidy operation, very nice – Rich Homolka Sep 24 '12 at 22:37

I had exactly the same issue yesterday :)

Additionally my drive was encrypted, and when I opened the file with Notepad++ it was all filled with NULLs. The problem is, if your drive is encrypted, there is no way to recover the data (apart from reading IL code and converting it back to C# from the compiled library). But, thankfully, all I needed to do was to check out original version from git hub.

I hope you did use source control. If you didn't, well this would be a good lesson.

  • 1
    Why would anyone post something like this if they could just svn revert (or equivalent) and it'd restore the file? – Daniel Beck Jun 24 '12 at 12:02
  • @DanielBeck the easiest way not to get into such situations is to commit often. My suggestion was to fix the root problem, rather than to fix a single failure. If one cannot update code from the repository, it is a much bigger trouble (given this is production code). – oleksii Jun 24 '12 at 12:11
  • @oleksii , hmm, I finally recover nearly 90% of my code by decompiling DLL file, and I learn my lesson, now I tried to SVN my project to a server, thanks... – Albert Gao Jun 25 '12 at 16:12

This is because the operation delete has happened on the file, and the code or data in your file is interrupted in the interim stage. It's not either committed to source safe or retained. Try getting older version and you have to write code again.

This happens sometimes even if your hard disk is not crashed


Here are a few steps you can do

  • try to recover the files "physically" via the free Recuva tool.

  • try to recover them from your temporary files folder in the user and files directory of windows

  • Try to look inside the (Global) Assembly Cache and disassemble back your application to C# via ILSpy

  • Thanks for reminder about ILSpy, you literary saved my as :) – KwahuNashoba Dec 26 '19 at 2:15

do you have your program exe file? .NET Reflector v6 provides support for .NET Framework 4.0 assemblies. Download it from here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.