Home » c# » c# – How to call windows runtime component from c++/cx uwp project?

c# – How to call windows runtime component from c++/cx uwp project?

Posted by: admin February 21, 2020 Leave a comment

Questions:

I created a C# runtime component based on Visual Studio template in the same solution with my C++/CX UWP project:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace httpServer
{
    public sealed class Class1
    {
        public int SampleProperty { get; set; }
    }
}

I added the reference to component to my C++/CX UWP project and created object as follows:

auto srv = ref new httpServer::Class1();

Solution compiles, but on this line I get an exception:

Exception thrown at 0x776A3DB2 in Bonsai Master UWP.exe: Microsoft C++
exception: EEFileLoadException at memory location 0x05598104.

onecore\com\combase\objact\dllcache.cxx(4713)\combase.dll!75CF6DE2:
(caller: 75CFE2BB) ReturnHr(1) tid(8408) 80131040 Exception thrown at
0x776A3DB2 (KernelBase.dll) in Bonsai Master UWP.exe: WinRT originate
error – 0x80131040 : ‘The text associated with this error code could
not be found.’.

How to&Answers:

It looks like a bug in Visual Studio 2019:
https://social.msdn.microsoft.com/Forums/windowsapps/en-US/6d0d04e8-1471-4343-a78e-65c6405080cc/winrt-component-works-in-c-but-not-in-c?forum=wpdevelop