How to replicate (we will use Windows Terminal as example):
Clone the Windows Terminal repo and fetch submodules
Create a C# Windows Runtime Component in the solution with a
UserControl
with some random controlsReference the C# WinRT Component from the project you want to host the
UserControl
inOpen an Xaml page in one of Windows Terminal projects (we will use
TerminalPage.xaml
fromTerminalAppLib
project as an example)Add the
UserControl
to that pageCompile and run (you might need to include the generated Xaml compiled files of the
UserControl
topch.h
file for it to compile without Xaml Compiler errors)You will find that the app will crash with
class not registered
exception
What I have tried:
Using
Class Library
instead ofWinRT Component
https://github.com/asklar/WinRTComponent/blob/master/README.md
Registering the class in
WindowsTerminal.manifest
file, like this (I used.dll
instead of.winmd
when I tried withClass Library
):
<file name="myWinRTComponent.winmd" hashalg="SHA1" xmlns:winrt="urn:schemas-microsoft-com:winrt.v1">
<winrt:activatableClass name="Namespace.UserControlClass" threadingModel="both" />
</file>
- Registering the class manually in
AppxManifest.xml
file
So I finally found the solution we have to register against
CLRHost.dll
instead of the Runtime Component Winmd fileSo if the app is packaged we have to add that inside the
Extensions
tag (which is inside thePackage
tag not the one that inside theApplication
tag) ofPackage.appxmanifest
(keeping in mind thatNamespace
is the namespace of the control and the Runtime Component name/assembly name &UserControlClass
is the name of theUserControl
class)And we have to add this to
Application.manifest
inside theassembly
tag if the app is unpackaged (keeping in mind thatApplication
is the name of the application &Namespace
is the namespace of the control and the Runtime Component name/assembly name &UserControlClass
is the name of theUserControl
class)