3
votes

I have a similar problem as previously reported (and unanswered successfully/unsolved) as below:

"If I create a new project in Visual Studio 2010 SP1 and select "WPF Application" it generates the application, but I get the error "The name 'InitializeComponent' does not exist in the current context" even before i build it. I get the same error when I try to build established projects. Yesterday, I had no problems with it. "

Im pretty sure that this issue is nothing to do with the project, source files or generated settings, but may have to do with a corrupt visual studio installation, registry, .net or windows itself because the same project (exactly the same) builds fine on my coleagues computer and vice-versa does not. Also, i have reinstalled Visual Studio, uninstalled & reinstalled, deleted & reinstalled, install-fixed from the microsoft disks and even tried manually deleting Visual studio/.net/C# and still get the problem. This issue is with both new WPF projects created with the wizard and with existing projects created weeks earlier.

The only option that seems to present itself now seems to be wiping my hard drive and reinstalling windows and Visual Studio again etc.

Any ideas regarding the fault or how best to wipe my system down to a level that will truly eradicate Visual Studio and its registry setting would be gratefully received ?

2
Thanks to everyone thats had a look at this issue, but i have now 'solved' it by restoring my entire PC (Windows 7 inclusive).user1578788

2 Answers

0
votes

I had the same problem and eventually discovered (after reinstalling VS and that had no effect) that by removing and re-installing the .Net frameworks the problem went away.

0
votes

There are two primary causes of this very common and annoying problem!

  1. The most common is the x:Class doesn't match up with the MainPage.xaml namespace. Make sure that x:Class in MainPage.xaml has the correct namespace.
  2. The second most common cause of this problem is that the "Build Action" is not set to "Page" for MainPage.xaml!

This happens with Silverlight or WPF and though it is a PITA when you don't know what caused it once you know what the problem is; it is a simple fix. One of those things we all have to learn the hard way, but thanks for Stack Overflow.

I wrote a blog article that has pictures and explains Initialize Component does not exist in current context problem.