After porting an old Silverlight application, I started getting compiler errors stating “The name ‘InitializeComponent’ does not exist in the current context”.
This was baffling and after poking around a bit, this is how I resolved it.
Note: My solution may be specific to my Silverlight installation and computer setup. I never quite know what the various bits are.
Essentially, the build is not generating the hidden partial classes named foo.g.cs for the application or page foo.xaml. These contain the InitializeComponent and are hidden files under the obj/Debug folder.
To fix the problem, right-click on the project with the errors and select “Unload”
Then right-click and select “Edit xxx”. This will load the project file xml in the IDE.
Locate the item <ItemGroup>, which is somewhere towards the bottom.
You will see blue squiggly lines under the Application element and the Page.
Change them to be <ApplicationDefinition Include=xxx> and <Page Include=xxx>
Note: There will be a blue squiggly line under <SilverlightApplication>true</SilverlightApplication>, but no need to fix that
Save the xml and right-click the Project and select Load. Say ok to unload open file and load and compile project.” Hopefully your problem was resolved.