We developed a runtime component in C# to be referenced by UWP app. The UWP is written in C++ and crashes when referencing our runtime class as follows:
Exception thrown at 0x00007FF96B46A799 in App1.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x0000002C18DFC690. HRESULT:0x80131040 The text associated with this error code could not be found.
WinRT information: The text associated with this error code could not be found.
The code is:
C++
MainPage::MainPage()
{
InitializeComponent();
auto t = ref new RuntimeComponent1::Class1();
}
C#
public sealed class Class1
{
}
To reproduce the issue just create C++ UWP app, C# runtime component, and try creating instance of the runtime class in the app.
This is an unexpected blocking issue of the highest priority for us. We in a dire need of a workaround.
UPDATE: The solution posted by FayWang works for Release, although you have to ignore some errors popping up on first build and compile it again. The Debug still doesn't work ending up in the exception below for XAML-based UserControl written in C# in a separate runtime library. Same user control works fine when imported in C# UWP app.
Exception thrown at 0x00007FF96B46A799 in SampleAppCpp.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x000000E7EC9FB4C0. HRESULT:0x80131522 The text associated with this error code could not be found.
Failing code:
template<typename T>
::Platform::Object^ ActivateType()
{
return ref new T;
}
Stack:
KernelBase.dll!00007ff96b46a799() Unknown
vcruntime140d_app.dll!00007ff956d38337() Unknown
vccorlib140d_app.dll!00007ff90cae9e03() Unknown
[External Code]
SampleAppCpp.exe!Platform::Details::IActivationFactory::ActivateInstance() C++
SampleAppCpp.exe!MyUserControlLib::View::View() C++
SampleAppCpp.exe!ActivateType<MyUserControlLib::View>() Line 21 C++
SampleAppCpp.exe!XamlTypeInfo::InfoProvider::XamlUserType::[Windows::UI::Xaml::Markup::IXamlType]::ActivateInstance() Line 472 C++
SampleAppCpp.exe!XamlTypeInfo::InfoProvider::XamlUserType::[Windows::UI::Xaml::Markup::IXamlType]::__abi_Windows_UI_Xaml_Markup_IXamlType____abi_ActivateInstance(Platform::Object ^ * __abi_returnValue) C++
Windows.UI.Xaml.dll!00007ff94b7d8116() Unknown
Windows.UI.Xaml.dll!00007ff94b774cad() Unknown
Windows.UI.Xaml.dll!00007ff94b94523e() Unknown
Windows.UI.Xaml.dll!00007ff94b85d25a() Unknown
Windows.UI.Xaml.dll!00007ff94b860cb9() Unknown
Windows.UI.Xaml.dll!00007ff94b85e4bc() Unknown
Windows.UI.Xaml.dll!00007ff94b85d7b6() Unknown
Windows.UI.Xaml.dll!00007ff94b797ae8() Unknown
Windows.UI.Xaml.dll!00007ff94b79770a() Unknown
Windows.UI.Xaml.dll!00007ff94b79702e() Unknown
Windows.UI.Xaml.dll!00007ff94b796e8c() Unknown
Windows.UI.Xaml.dll!00007ff94b796d5f() Unknown
Windows.UI.Xaml.dll!00007ff94b796cba() Unknown
SampleAppCpp.exe!Windows::UI::Xaml::IApplicationStatics::LoadComponent(Platform::Object ^ __param0, Windows::Foundation::Uri ^ __param1, Windows::UI::Xaml::Controls::Primitives::ComponentResourceLocation __param2) C++
SampleAppCpp.exe!Windows::UI::Xaml::Application::LoadComponent(Platform::Object ^ __param0, Windows::Foundation::Uri ^ __param1, Windows::UI::Xaml::Controls::Primitives::ComponentResourceLocation __param2) C++
SampleAppCpp.exe!SampleApp::MainPage::[SampleApp::__IMainPagePublicNonVirtuals]::InitializeComponent() Line 26 C++
SampleAppCpp.exe!SampleApp::MainPage::MainPage() Line 27 C++
[External Code]
SampleAppCpp.exe!SampleApp::App::[Windows::UI::Xaml::IApplicationOverrides]::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs ^ e) Line 68 C++
[External Code]