2010-11-02 24 views
7

有时候,我遇到的是,当我尝试使用内置在Visual Studio重构的选择,我得到一个对话框,说重命名一个属性:C#令人费解的错误:文件“”不能重构

The file '' could not be refactored. Object reference not set to an instance of an object.

Do you wish to continue with the refactoring?

[ ] Ignore further refactoring errors [ Yes ] [ No ]

该对话框在引用文件时实际显示空撇号。 Google不提供任何帮助。我开始认为这是一个晦涩的Visual Studio错误,我应该将其报告给Microsoft Connect。以为我会看到你们中的任何一个人在第一次遇到它之前。

仅供参考,我的解决方案/项目打造的很好。该属性未在任何XAML中引用。我尝试删除我的“.suo”文件,我的“bin”目录和我的“obj”文件夹,然后重建,但仍然没有骰子。我有最新的Microsoft更新。 Visual C#2008 Express和Visual Studio 2008 Professional都出现此问题。虽然它不应该的问题,物业是这样的:

private MigrationRequestViewModel Request 
{ 
    get; 
    set; 
} 

我没有问题,在同一个文件中的同一类重命名其他属性,比如这个:

private MigrationRequestViewModel RequestSnapshot 
{ 
    get; 
    set; 
} 

任何想法?请注意,我意识到我可以找到对该属性的所有引用并手动将其重命名,但我想深入此错误对话框的底部。

+1

这是C++吗?看起来更像是你在问C#。 – birryree 2010-11-03 00:00:33

+0

“Visual C#2008 Express和Visual Studio 2008 Professional出现问题”< - 所以是C#。 – 2010-11-03 00:02:12

+0

对不起,我的脑海里同时存在太多东西 – Fabian 2010-11-03 00:05:09

回答

4

如果你只是GOOGLE上搜索,你会发现在CodeProject你的问题这是已经公布超过半年前的一个字的字相同的副本错误消息:

Obscure Error: The File '' Could Not Be Refactored

的,作者问题提交到Connect,微软承诺在未来的版本中修复它:

Thanks for your feedback. We're aware of this issue. This issue will not be fixed in any VS2008 patches. Also, this issue also exists in Visual Studio 2010. However, we will strongly consider addressing this issue in a future release.

As a workaround, you may be able to get the refactor to work by first loading any XAML file that exists in your project.

If you have any other questions or issues, feel free to contact me directly. My email is ramatthi (at) microsoft (dot) com.

+0

+1此错误在Visual Studio 2010 10.0.30319.1 RTMRel中仍然有效。解决方案是确保在重构​​期间打开任何XAML文件。 – Sabuncu 2014-05-08 16:31:08

+0

Visual Studio Enterprise 2015中仍存在Bug。 – BaBu 2016-01-26 11:46:45

+1

VS 2017中仍然存在错误。 – 2017-03-11 02:45:56