4

I see this namespace:

System.Runtime.InteropServices.WindowsRuntime

Which provides interop between .NET and WindowsRuntime.

For instance, you can invoke a method in WindowsRuntime when you create a Metro application, as Metro uses WindowsRuntime, like

Windows.System.UserProfile.UserInformation

But when you create a normal .NET console application or WPF application, you can no longer directly reach WindowsRuntime namespaces such as Windows.System

I wonder if it were possible to invoke WindowsRuntime methods by using interop in the above-mentioned namespace.

A lot of thanks in advance!

user1343145
  • 217
  • 2
  • 5

2 Answers2

3

A .NET console mode app or a WPF app are not Metro applications. They can only run on the 'regular' version of Windows. The traditional desktop in the case of Windows 8. So can't interop with WinRT, it isn't loaded in the process. Targeting WinRT requires selecting a specific Metro project template when you start your project.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
1

You need to add this to the project file:

<PropertyGroup>
  <TargetPlatformVersion>8.1</TargetPlatformVersion>
</PropertyGroup>

For more details, see How to use specific WinRT API from Desktop apps.

Luis Cantero
  • 1,278
  • 13
  • 11