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
UserControlwith some random controlsReference the C# WinRT Component from the project you want to host the
UserControlinOpen an Xaml page in one of Windows Terminal projects (we will use
TerminalPage.xamlfromTerminalAppLibproject as an example)Add the
UserControlto that pageCompile and run (you might need to include the generated Xaml compiled files of the
UserControltopch.hfile for it to compile without Xaml Compiler errors)You will find that the app will crash with
class not registeredexception
What I have tried:
Using
Class Libraryinstead ofWinRT Componenthttps://github.com/asklar/WinRTComponent/blob/master/README.md
Registering the class in
WindowsTerminal.manifestfile, like this (I used.dllinstead of.winmdwhen 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.xmlfile
So I finally found the solution we have to register against
CLRHost.dllinstead of the Runtime Component Winmd fileSo if the app is packaged we have to add that inside the
Extensionstag (which is inside thePackagetag not the one that inside theApplicationtag) ofPackage.appxmanifest(keeping in mind thatNamespaceis the namespace of the control and the Runtime Component name/assembly name &UserControlClassis the name of theUserControlclass)And we have to add this to
Application.manifestinside theassemblytag if the app is unpackaged (keeping in mind thatApplicationis the name of the application &Namespaceis the namespace of the control and the Runtime Component name/assembly name &UserControlClassis the name of theUserControlclass)