Wednesday, April 4, 2018

'InitializeComponent' is not declared

I started getting this compilation error after refactoring some base classes and checking my code in through TFS. I got a clean compile before the check-in, but after checking the code in, getting latest, and rebuilding, I started getting this error on certain pages but not others.


This happens when your XAML class does not match your code-behind's class or if the base class doesn't inherit from UserControl, Window, or Page. For example, if you inherit from FrameworkElement, you will see the same error plus a lot more.

<FrameworkElement x:Class="APYDirectPaymentNewAdd"

             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

Public Class APYDirectPaymentNewAdd
    Inherits Windows.FrameworkElement


This wasn't the case. My class ultimately inherited from UserControl. I checked three times!

After a lot of head scratching I remembered I had performed a manual merge on the project file during the check-in and realized the XAML files were now excluded from the project. I re-included them and everything worked correctly. Only some of them had been excluded which is why only a few pages showed this error.


No comments:

Post a Comment