cppwinrt: Unable to add C++/WinRT Runtime Component to UWP C# Application

Just want to make sure that I’m not doing something wrong here. I have created a Runtime Component project , implemented a bare minimum of a single Runtime class (following the example here: https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/author-events), but i could not reference this project from a C# UWP Application within the same solution. Trying to add a reference to the project would just end up with the message of The method or opration is not implemented . Is this a known issue with Visual Studio or C++/WinRT? Project referencing from a C++/WinRT Blank application doesn’t have this issue.

Directly referencing the winmd files under Debug\Merged\ will just result in a runtime exception of something not activated class.

Also, if i tried to manually reference the project by editing the csproj file manually, I have 2 cases happening. One project works just fine and the other one is complaining about not having the DLL of the Runtime Time component under its Debug folder.

I can try to upload both projects here (the one that kinda-works and the one that doesn’t) later but if anybody have any pointers, that would be great.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (3 by maintainers)

Most upvoted comments

This scenario should definitively be formally documented somewhere. Thanks to the information I found here, I was able to make it work but I believe this is going to become too common for a developer to be lucky enough and find this page. Additionally, it seems that several things can influence the proper reference to the .winmd and .dll file from the C# projects. Or is it well documented and I have not found it? 😉

@Code-ScottLe - note that this scenario requires reg-free winrt activation from the C# app. I don’t see that in you package.appmanifest. For details, see: https://github.com/microsoft/xlang/wiki/Referencing-a-Windows-Runtime-component-from-a-Desktop-app

I was able to get the attached sample working with the two edits mentioned in the wiki page above:

App1.csproj:

  <ItemGroup>
    <ProjectReference Include="..\BankAccountWRC\BankAccountWRC.vcxproj" />
  </ItemGroup>

Package.appxmanifest:

  <Extensions>
    <Extension Category="windows.activatableClass.inProcessServer">
      <InProcessServer>
        <Path>BankAccountWRC.dll</Path>
        <ActivatableClass ActivatableClassId="BankAccountWRC.BankAccount" ThreadingModel="both"/>
      </InProcessServer>
    </Extension>
  </Extensions>