This blog has, IMO, some great resources. Unfortunately, some of those resources are becoming less relevant. I'm still blogging, learning tech and helping others...please find me at my new home on

Friday, July 10, 2009

Refactoring Woes

I just ran into a problem that was very hard to source related to refactoring class names in Visual Studio 2008.  The error I started getting was as follows:

The name 'InitializeComponent' does not exist in the current context.

I didn’t start to get this error until after I restarted Visual Studio. Also of note is that I run Blend and Visual Studio side-by-side, so it added some extra “what happened?” to the situation.

I was working in a WPF application and moving some classes around into various namespaces.  I had both VS and Blend 2 open at the time and after a build (which compiled and ran just fine) I switched over to Blend, which prompted me to reload the project (which I did).  At that point, I started getting three or more errors for each user control and view in my project.

I quit Blend without saving, thinking that it just crapped out hard for some unknown reason.

Visual Studio then prompted me to reload the project, which I did – reluctantly – and everything still compiled okay.  I thought that fixed the previous (non-descript) errors, but a clean & rebuild killed the project (80+ errors again).

The problem ended up being a problem with the refactoring.  Some of the classes were renamed/moved to the new namespaces, but only some, and all the Xaml partial classes were left in half-baked states. 

If you run into this, I suggest a manual approach rather than a find-and-replace as quick action in that regard might lead to further complications (I have on occasion gotten into trouble with a quick finger on the rename trigger).

After finding the 6 or so classes that were only halfway renamed the project healed itself fairly quickly.

No comments:

Post a Comment