尝试从C ++ UWP应用程序引用C#UWP类库中的方法时,出现COMException。这是最基本的设置所发生的,所以我一定做错了。
复制:
public static int GetNumber() { return 22; }
using namespace ClassLib;
MainPage::MainPage()
{
InitializeComponent();
auto foo = Class1::GetNumber();
}
Exception thrown at 0x76984402 in UWPApp.exe:
Microsoft C++ exception:
Platform::COMException ^ at memory location 0x0421DD44.
HRESULT:0x80131040 The text associated with this error code could not be found.
此问题是由于从C ++ / CX或C ++ WinRT项目中调用基于.net的WinRT组件引起的。要使其工作,您可以Microsoft.Net.Native.Compiler
在您的c ++ / cx项目中添加nuget软件包并首先安装它。然后右键单击项目->卸载项目->编辑.vcxproj。之后,在其中添加以下属性。
<PropertyGroup>
<UseDotNetNativeToolchain Condition="'$(Configuration)'=='Release'">true</UseDotNetNativeToolchain>
<DotNetNativeVersion>2.2.3</DotNetNativeVersion>
</PropertyGroup>
请注意,用您安装的Microsoft.Net.Native.Compiler nuget软件包的版本替换上面的2.2.3版本。有关它的更多详细信息,您可以参考此类似线程。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句