June 5th, 2019

Why does my C++/WinRT project get errors of the form ‘winrt::impl::produce<D, I>‘: cannot instantiate abstract class, missing method GetBindingConnector

So your C++/WinRT project gets build failures of the form

base.h(8208): error C2259: 'winrt::impl::produce<D, I>': cannot instantiate abstract class
with
[
    D=winrt::YourNamespace::implementation::YourClass,
    I=winrt::Windows::UI::Xaml::Markup::IComponentConnector2
] (compiling source file YourClass.cpp)
base.h(8208): note: due to following members: (compiling source file YourClass.cpp)
base.h(8208): note: 'int32_t winrt::impl::abi<winrt::Windows::UI::Xaml::Markup::IComponentConnector2, void>::type::GetBindingConnector(int32_t, void *, void **) noexcept': is abstract (compiling source file YourClass.cpp)

Normally, the Get­Binding­Connector function is defined in YourClass.xaml.g.hpp, but that header file isn’t being generated.

What’s going on, and how do you fix it?

The problem is that you forgot to include the header file

#include "winrt/Windows.UI.Xaml.Markup.h"

Add that line to, say, your precompiled header file, and things should work again.

You are likely to run into this problem when upgrading a project from C++/WinRT 1.0 to C++/WinRT 2.0. The C++/WinRT 2.0 compiler is much better about reducing header file dependencies, which improves build times. If you forgot to include winrt/Windows.UI.Xaml.Markup.h in a C++/WinRT 1.0 project, you often got away with it, because some other C++/WinRT 1.0 header file you included happened to include winrt/Windows.UI.Xaml.Markup.h as a side effect. You were getting a free ride on the other header file.

 

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

1 comment

Discussion is closed. Login to edit/delete existing comments.

  • cheong00

    Not written C++/WinRT project before, but I wonder whether these header files should already be included in the project when you start with “Windows Desktop Application (C++/WinRT)” template.