2010-11-02 85 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