Peter Vermilye
Peter Vermilye

Reputation: 43

Internal error WMC9999 unable to convert types

I installed vs2022 v17.12 and soon after upgraded to 17.13.2. I have installed the NuGet package and all the other stuff (I'm pretty sure).

I created a new C++/WinRT/UI3.0 app using all the wizard stuff. I built the solution unchanged, and everything worked just fine.

Next, I wanted to create a Custom User Control. I went to Project > Add New Item > Visual C++ > Blank User Control (C++/WinRT) and created a blank user control.

I gently touched the resulting files and put a <Button> within a <StackPanel> element in the <UserControl> element of the .xaml file. I named it MyNewButton (x:Name="MyNewButton").

When I built my project (tried Build, then Rebuild, and finally tried Clean and then Build), I get an Unhelpful error message:

1>C:\Users\vermi\source\repos\CPP\SecondCppWinRTApp\SecondCppWinRTApp\BlankUserControl.cpp(11,47): warning C4100: 'value': unreferenced formal parameter
1>(compiling source file '/BlankUserControl.cpp')
1>C:\Users\vermi\source\repos\CPP\SecondCppWinRTApp\packages\Microsoft.WindowsAppSDK.1.6.250205002\build\Microsoft.UI.Xaml.Markup.Compiler.interop.targets(660,9): Xaml Internal Error error WMC9999: Unable to cast object of type 'System.Xaml.XamlType' to type 'Microsoft.UI.Xaml.Markup.Compiler.DirectUI.DirectUIXamlType'.

None of the AI Bots offer any useful suggestions except to check my xaml syntax. All to no avail. I have not tried to USE my custom control within my main page so I haven't adjusted any of my original files. I have tried to tweak and prod the code files but it always boils down to the same error message in the same place.

This is my second attempt to create a modern C++ desktop app using WinRT and UI3.0. My first attempt was to build just the desktop app out-of-the-box. That works fine, not very exciting, but it works. Perhaps it's silly of me to think I can use the wizards to get a framework to hang more code on and expect it to build and run without any intervention on my part. I mean when I learned C using K&R, I could get the "Hello, World" first app to run as is.

Does anyone have any ideas to help?

Thanks in advance.

Peter

Update 2: Here are the code files I am struggling with. The project I am working from was created as a Blank App, Packaged (WinUI 3 in Desktop). I have done nothing to those files. I am simply trying to add a Blank User Control (C++/WinRT) to this project. When these files are included, I get the WMC9999 error message shown above. When I exclude them, the project builds and executes just fine.

BlankUserControl.xaml

<UserControl
    x:Class="SecondCppWinRTApp.BlankUserControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SecondCppWinRTApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
        <Button x:Name="MyButton" Click="MyClickHandler">Click Me Control</Button>
    </StackPanel>
</UserControl>

BlankUserControl.cpp

#include "pch.h"
#include "BlankUserControl.h"
#if __has_include("BlankUserControl.g.cpp")
#include "BlankUserControl.g.cpp"
#endif

using namespace winrt;
using namespace Windows::UI::Xaml;

namespace winrt::SecondCppWinRTApp::implementation
{
    int32_t BlankUserControl::MyProperty()
    {
        throw hresult_not_implemented();
    }

    void BlankUserControl::MyProperty(int32_t /* value */)
    {
        throw hresult_not_implemented();
    }

    void BlankUserControl::MyClickHandler(IInspectable const&, RoutedEventArgs const&)
    {
        MyButton().Content(box_value(L"Clicked"));
    }
}

BlankUserControl.h

#pragma once

#include "winrt/Windows.UI.Xaml.h"
#include "winrt/Windows.UI.Xaml.Markup.h"
#include "winrt/Windows.UI.Xaml.Interop.h"
#include "winrt/Windows.UI.Xaml.Controls.Primitives.h"
#include "BlankUserControl.g.h"

namespace winrt::SecondCppWinRTApp::implementation
{
    struct BlankUserControl : BlankUserControlT<BlankUserControl>
    {
        BlankUserControl() 
        {
            // Xaml objects should not call InitializeComponent during construction.
            // See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent
        }

        int32_t MyProperty();
        void MyProperty(int32_t value);

        void MyClickHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);
    };
}

namespace winrt::SecondCppWinRTApp::factory_implementation
{
    struct BlankUserControl : BlankUserControlT<BlankUserControl, implementation::BlankUserControl>
    {
    };
}

And finally, BlankUserControl.idl

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

I renamed the method and the name of the control to avoid any conflict with the boilerplate main app.

If necessary, I can include all the other files as well, but they should be just as available to anyone by creating the blank app in your own copy of VS 2022.

Thanks again!

Peter

Update 3: As a lark, I added a new item but used the User Control (WinUI 3) selection instead of the Blank User Control (C++/WinRT) selection. NOW everything works as I would have originally hoped. The structure is similar (although the .cpp and .h files are now .xaml.cpp and .xaml.h). The code inside each of these files is also similar, but the namespaces and #includes are subtly different. The ones I noticed, changed from Windows.xxxx to Microsoft.xxxx. Yes, I fully understand that the differences must be fundamentally different, but the error diagnosis is of no help whatsoever. And running the errors in Verbose didn't yield anything about WHY I was getting the error. I can see from the error and my fresh code how the original code files wouldn't work (it DOES say that in the error message, but it was meaningless to me. Easy to say now that I see the difference).

I hope this will help some other new person who goes down that rabbit hole.

Thanks everyone.

Upvotes: 0

Views: 42

Answers (0)

Related Questions