question

Attila-5686 avatar image
0 Votes"
Attila-5686 asked ·

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

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

windows-uwp-runtime
· 2
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

When I tried to create a c++/winrt desktop application and followed the tutorial to try to call the c# component, also failed. But I'm not sure if it can call the c# component or my steps do not apply for calling c# component, so I will ask the team about this.

0 Votes 0 · ·

@Attila-5686 Does Fay's reply make sense? Please feel free if you have other questions.

1 Vote 1 · ·
FayWang-MSFT avatar image
1 Vote"
FayWang-MSFT answered ·

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.

· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AlexanderSklar avatar image
1 Vote"
AlexanderSklar answered ·

@Attila-5686 :
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

· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.