[C++/WinRT][WPF] Unable to use Windows Runtime Component from WPF app (CO_E_ERRORINDLL).

Maarten van Sambeek 1 Reputation point
2020-09-04T06:46:59.81+00:00

Hi!

I made a Windows Runtime Component which I want to use in a WPF application. I created the WinRT component using C++/WinRT, and I am able to use it from a C# UWP application (it loads and I can call methods).

Now I try to add it as a reference to a NetCore 3.1 WPF project, but as soon as I try to create an instance of the component (it has a constructor), I get the following error:

System.Runtime.InteropServices.COMException: 'Error in the DLL (0x800401F9 (CO_E_ERRORINDLL))'

I added a manifest with the following section:

      <file name="RuntimeComponent2.winmd" xmlns:winrt="urn:schemas-microsoft-com:winrt.v1">
          <winrt:activatableClass name="RuntimeComponent2.Class1" threadingModel="both" />
      </file>

I also tried creating a runtime component in C#, which does work (using the section above), but I need it to be a C++/WinRT component.

My guess is it has something to do with the VC Redistributables, I also followed the steps in Enhancing Non-packaged Desktop Apps using Windows Runtime Components and I added the Microsoft.VCRTForwarders.140 package.

Do you have any suggestions?

Kind regards,

Maarten van Sambeek

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,760 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Will 81 Reputation points Microsoft Employee
    2020-10-20T08:47:32.247+00:00

    hi Maarten,

    Could you try to use this manifest code:

      <file name="WinRTComponent.dll">
        <activatableClass
            name="WinRTComponent.Class"
            threadingModel="both"
            xmlns="urn:schemas-microsoft-com:winrt.v1" />
      </file>
    

    Any updates, please let me know.
    BR,
    Will

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.