c++visual-studioxamluwpinitializecomponent

UWP crashes at InitializeComponent() [C++]


This is the weirdes error I've gotten so far while working on UWP. I was happily working when I ran my code to check some new changes. After the app executed the InitializeComponent() method it crashed. I went on the debugger mode and tried to narrow down what could be the cause of the problem.

The InitializeComponent() function looks like this:

    void ::SDKTemplate::Scenario3_DataBaseHandling::InitializeComponent(){
    if (_contentLoaded)
    {
        return;
    }
    _contentLoaded = true;
    ::Windows::Foundation::Uri^ resourceLocator = ref new ::Windows::Foundation::Uri(L"ms-appx:///Scenario3_DataBaseHandling.xaml");
    ::Windows::UI::Xaml::Application::LoadComponent(this, resourceLocator, ::Windows::UI::Xaml::Controls::Primitives::ComponentResourceLocation::Application);
}

After a few attempts I found that the error was coming after the last line was executed:

  ::Windows::UI::Xaml::Application::LoadComponent(this, resourceLocator, ::Windows::UI::Xaml::Controls::Primitives::ComponentResourceLocation::Application);

I am quite new to UWP programming so I don't understand what is the problem. From what I read on the documentation this line loads the components used on the XAML. But I don't understand why this problem is suddenly appearing now or its nature.

Could anyone give me directions to solve my problem?


Solution

  • My problem came with my XAML code, I was trying to apply a "Style: TextBlockStyle" to a TextBox.