C++/WinRT Problems Calling C#/WinRT Method

JRH3221 0 Reputation points
2023-07-23T05:27:42.3533333+00:00

I was following the tutorial Authoring a C# Windows Runtime component for use from a C++/WinRT app, it compiles correctly with no issues, but before the program properly initializes it crashes.

The exception thrown is "Microsoft C++ exception: winrt::hresult_error at memory location", the hresult value upon the debugger break, is "0x80131040 : The located assembly's manifest definition does not match the assembly reference."

I checked the Nuget packages to make sure they are all up to date, as well as visual studio itself. Both the UWP and the WinRT project are targeting the same windows version, so i'm out of ideas on how to resolve this issue.

This issue only occurs when i have the line"winrt::SampleComponent::Example myExample;" in my header file. As mentioned before, everything is seemingly fine at compile time, with the c# namespace and class being recognized, it's just when the program opens things go wrong.

Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,636 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JRH3221 0 Reputation points
    2023-07-23T05:42:19.8833333+00:00

    I figured out the issue after re-reading the tutorial. In a note box it says to "On the New Universal Windows Platform Project dialog box, choose Windows 10 Creators Update (10.0; Build 15063) as the Minimum Version.", I didn't think this was necessary as i was targeting a higher minimum version. Now i wonder why needing support for a lower version would be necessary, as newer version should include everything that is in the previous?

    0 comments No comments