[C++/WinRT] loading a Windows Runtime Component (reg free) written in C#

Attila 41 Reputation points
2020-03-04T21:04:32.437+00:00

I wonder if it is possible to use C++/WinRT to load a Windows Runtime Component implemented in C# (resulting a .winmd) file. It looks like it should be possible, but at runtime I'm getting a Class Not Available exception.

I've spent a long time trying to make the reg free technique work, by following this post

https://blogs.windows.com/windowsdeveloper/2019/04/30/enhancing-non-packaged-desktop-apps-using-windows-runtime-components/

and by trying to adopt the code found here

https://github.com/Microsoft/RegFree_WinRT

I have posted my compiling but failing solution on Github, with some procmon diagnostic, showing that the C++ application is looking in the right .winmd file, but apparently, the class is not found?

https://github.com/szarvas/regfree_winrt_fail

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Fay Wang - MSFT 5,191 Reputation points
    2020-03-09T08:37:58.237+00:00

    Hello,

    ​Welcome to our Microsoft Q&A platform!

    Currently only native UWP app to managed UWP component activation is supported. This means if you want to manage c# component from C++/WinRT, you need to create a C++ UWP app(e.g. C++/WinRT UWP app) and set the min target version of the C# project to 15063 or earlier. In that case, you can call the c# component from C++/WinRT UWP app.

    But for native desktop (non-packaged) app(C++) activating c# runtime component, currently it is not supported.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. AlexanderSklar 11 Reputation points
    2020-04-22T01:02:58.833+00:00

    @Attila :
    I actually have a solution for >15063:
    We've identified a fix and we're pursuing a public doc update.
    In the meantime here's how to consume a C# WinRT component from C++/WinRT

    Thanks,
    -Alex

    1 person found this answer helpful.
    0 comments No comments