Calling C # component from JavaScript in Windows 10 Universal App

I am trying to use the Windows Runtime component (C #) in my universal Windows 10 application (JavaScript). I found how to do this in applications for Windows 8.x applications: https://msdn.microsoft.com/en-us/library/hh779077.aspx but this solution does not work with the Windows 10 Universal App. This throws an exception that the class is not registered in JavaScript.

WRC Code:

namespace SampleComponent { public sealed class Example { public static string GetAnswer() { return "The answer is 42."; } public int SampleProperty { get; set; } } } 

In JS:

  document.getElementById('output').innerHTML = SampleComponent.Example.getAnswer(); 
+5
source share
2 answers

Any CPU mode is not available (by default) if you are developing a Windows 10 application written using XAML / C #, or an application written using HTML / JS using a WinRT component written in C # because of .Net native "

You need to configure the target platform :)

+1
source

After some research, I found that this problem occurs when building in any processor mode. For x86 / x64, it works correctly. Currently this solution is enough for me. I will write additional information here if I could find how to run it on other platforms.

+1
source

Source: https://habr.com/ru/post/1237395/


All Articles