Skip to content

"T must be WinRT type" error for GUID properties #412

@osolo

Description

@osolo

Adding GUID properties in an .idl files leads to the following error:

C2338 T must be WinRT type.

Sample .idl:

namespace CppWinRTXaml
{
    [default_interface]
    runtimeclass BlankUserControl : Windows.UI.Xaml.Controls.UserControl
    {
        BlankUserControl();
        Guid MyProperty;
    }
}

The error stems from the generated XamlTypeInfo.Impl.g.cpp using GUID and not the newer winrt::guid class:


const MemberInfo MemberInfos[] = 
{
    //   0 - CppWinRTXaml.BlankUserControl.MyProperty
    L"MyProperty",
    &GetValueTypeMember_MyProperty<::winrt::CppWinRTXaml::BlankUserControl, GUID>,
    &SetValueTypeMember_MyProperty<::winrt::CppWinRTXaml::BlankUserControl, GUID>,
    0, // Guid
    -1,
    false, false, false,
};

As a temporary workaround, I added the following to my pch.h (but I cannot guarantee correctness):

namespace winrt
{
    template <>
    inline Windows::Foundation::IInspectable box_value<GUID>(GUID const& value)
    {
        return Windows::Foundation::IReference<winrt::guid>(winrt::guid(value));
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions