11

我对 Visual Studio 2010 有一个非常奇怪的问题。

我的程序有一些内存问题,所以我必须经常重启。上次重新启动后,我的一个头文件已自动损坏,现在只能通过记事本打开(甚至从 Visual Studio 的内部环境中,在调试时(它只显示我只显示汇编代码)或当我去此文件的文件夹并执行“使用 Visual Studio 打开”,它仍然是打开它的记事本)。

我在 Microsoft 论坛中发现了问题,但那里没有任何解决方案的想法。

4

5 回答 5

11

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

于 2015-01-28T19:56:31.470 回答
6

如果 Visual Studio 无法识别文件的编码,如果文件已损坏(在我的情况下是由于电源故障),通常会出现这种情况,它将默认使用记事本打开文件。

虽然@Sammler 很幸运,他损坏的文件是可以恢复的(通过在更宽容的文本编辑器中打开半损坏的文件),但不能保证会出现这种情况,您可能会因为丢失工作/文件而陷入困境内容。

于 2015-02-05T07:50:36.333 回答
2

同样的事情发生在我身上。

这发生在我的 Windows VM 无响应之后。在我的 Mac 上使用 VMWare Fusion,我做了一个“强制关机”。当它恢复时,我正在处理的文件正在记事本中打开,并且似乎是空白的。

我用记事本++打开文件,发现文件内容只是一串NUL字符(以深色背景显示的字符)。我确定 VS 看到了这一点,并决定要注意显示损坏的数据。显然,强制关闭造成了这种情况,所以我唯一的办法就是从源代码管理中获取备份。

于 2015-04-06T13:44:09.857 回答
2

如果您的文件中有空终止字符,则可能会发生这种情况(又名“\0”)

于 2019-12-31T05:45:33.490 回答
0

也发生在我身上。我的文件——出于某种原因——被保存为 UNICODE,而不是像我的所有其他项目文件一样保存为 ANSI。只需使用记事本保存为 ANSI。

于 2020-05-12T11:43:18.077 回答