Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Obscure error: file '' could not be refactored

Sometimes, I come across a property that, when I try to rename it using the built-in Visual Studio refactoring option, I get a dialog that says:

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 ]

The dialog actually shows empty apostrophes when referring to the file. Google doesn't provide any help. I'm beginning to think this is an obscure Visual Studio bug and that I should report it to Microsoft Connect. Thought I'd see if any of you have come across it before first.

FYI, my solution/projects build fine. The property is not referenced in any XAML. I tried deleting my ".suo" file, my "bin" directory, and my "obj" folder, then rebuilding, but still no dice. I have the latest Microsoft updates. The problem occurs with both Visual C# 2008 Express and Visual Studio 2008 Professional. Though it should not matter, the property looks like this:

private MigrationRequestViewModel Request
{
    get;
    set;
}

I have no problem renaming other properties in the same class in the same file, such as this one:

private MigrationRequestViewModel RequestSnapshot
{
    get;
    set;
}

Any ideas? Note that I realize I could just find all reference to the property and manually rename it, but I'd like to get to the bottom of this error dialog.

like image 630
Fabian Avatar asked Nov 02 '10 23:11

Fabian


1 Answers

If you just googled the error message you would have found a word-by-word identical copy of your question on CodeProject which was posted already more than half a year ago:

Obscure Error: The File '' Could Not Be Refactored

The author of that question filed it on Connect and Microsoft promised to fix it in a future release:

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.

like image 81
Dirk Vollmar Avatar answered Oct 10 '22 19:10

Dirk Vollmar