11

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.

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
Bartolinio
  • 780
  • 2
  • 8
  • 17
  • 3
    Have you tried the solution posted in your link? "Save the file as Unicode" – Johannes Kommer Nov 01 '11 at 21:09
  • You have to reboot because of memory issues in a *program*? Is it running in a privileged mode? – thkala Nov 01 '11 at 21:15
  • Well, the program might take all the memory space and then reboot is the only option that I know :( about the unicode- didn't find this option on my nodepad, but a friend just told me that maybe notpad++ will come to my rescue, Im trying it now. – Bartolinio Nov 01 '11 at 21:20
  • notepad -> save as -> encoding -> Unicode – Johannes Kommer Nov 01 '11 at 21:23
  • Hey, I managed to open the file in visual with the help of notepad++....J. Kommer- Many Many Thanks! However the file is still corrupted so I have to re-write some methods :( Valmods- Thanks on your help with the corruptions, I will try to see with those programs what hapened. – Bartolinio Nov 01 '11 at 21:32
  • The link in the question pointing to microsoft is now a 404. Any other link? – Xavi Montero Jan 13 '16 at 21:15

5 Answers5

12

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).

Sammler
  • 121
  • 1
  • 3
  • 1
    Non-printable characters will cause exactly this effect. I had a text file with one ASCII char 27 at the end and both Visual Studio 2012 and 2015 spit it out to Notepad. – Mike Nov 28 '16 at 21:19
7

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.

david.barkhuizen
  • 5,239
  • 4
  • 36
  • 38
3

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

zezba9000
  • 3,247
  • 1
  • 29
  • 51
  • Wow, great answer. I did not realize the answer was this simple. My text editor can find such characters and it found one, it worked just fine after I removed it. I was using the latest Visual Studio that I downloaded this week and it was launching 6 instance of notepad, now the issue is gone – faljbour Dec 03 '20 at 00:31
2

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.

lipidfish
  • 356
  • 4
  • 11
0

Also happened to me . My file - for some reason - was saved as UNICODE and not in ANSI like all my other project files. Just save as ANSI using notepad .

Nir
  • 1