Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio file opens only with notepad

I have a very strange issue with Visual Studio 2010.

My program have some memory issues, so I have to reboot frequently. After the last reboot, one of my header files has been corrupted automatically, and can be opened now only by notepad (even from the internal environment of Visual Studio, while debuuging (it only shows me only the assembly code) or when I go to this file's folder and do "Open with Visual Studio", its still notepad that opens it).

I found the problem in the Microsoft Forums, but there isn't any idea for solution there.

like image 950
Bartolinio Avatar asked Nov 01 '11 21:11

Bartolinio


4 Answers

If you have null terminating characters in your file this can happen (aka '\0')

like image 87
zezba9000 Avatar answered Oct 16 '22 12:10

zezba9000


I recently had the same problem. I believe the file is corrupted with non-printing characters; it looks fine in Notepad except every line is indented by one space.

To resolve the issue, I had to open the file in notepad, then remove/delete the original, recreate it by adding a new item to the project, and copy in the contents of the old file from Notepad.

I am using VS Express 2013, which imposes its own formatting on pasted-in text, so the indentation disappeared at this point. Mercurial doesn't show any diffs between the corrupted and new files (except for some code I just added).

like image 32
Sammler Avatar answered Oct 16 '22 11:10

Sammler


If Visual Studio is not able to recognise the encoding of the file, which will generally be the case if the file has become corrupted (in my case due to a power failure), it will default to using notepad to open the file.

While @Sammler is lucky in that his corrupted file was recoverable (via opening the semi-corrupted file in a more tolerant text editor), there is no guarantee that this will be the case, and you may be stuck with losing the work / file contents.

like image 7
david.barkhuizen Avatar answered Oct 16 '22 11:10

david.barkhuizen


Same thing happened to me.

This occurred after my Windows VM became unresponsive. Using VMWare Fusion on my Mac, I did a "Force Shutdown". When it came back up, the file I was working on was opening up in Notepad, and appeared to be blank.

I opened the file using Notepad++, and found that the file contents were only a string of NUL characters (characters showing with the dark background). I'm sure VS saw this and decided it wanted noting to do with displaying the corrupted data. Obviously the Force-Shutdown created this situation, so my only recourse was to get a backup from source control.

like image 2
lipidfish Avatar answered Oct 16 '22 10:10

lipidfish