2

I met an UWP issue, and asked question as below post: How to detect user idle in UWP?

Thanks for Nico to answer my question! And he provided an example code here: https://stefanwick.com/2018/05/15/global-hotkey-registration-in-uwp/ https://github.com/StefanWickDev/ExtensionGallery/tree/master/GlobalHotkey

Some of the codes which report compile errors are:

using Windows.ApplicationModel;
using Windows.ApplicationModel.AppService;
using Windows.ApplicationModel.Core;
using Windows.Foundation.Collections;
using Windows.Storage;

But I cannot run the above code, I mean the GlobalHotkey project. I got 18 compile errors as below picture shown. enter image description here

The first error is:

The type or namespace name 'ApplicationModel' does not exist in the namespace 'Windows'

I cannot find Windows.ApplicationModel by this way:

Project -> Right Click -> Add -> Reference -> Assemblies -> Search "System.Drawing"

Like this picture shown: enter image description here

And I did not change the code at all. I also install the SDK Build 17134, which is required by the original code. Why?

More: To answer Pavel Anikhouski's question, please check below picture. I have the two files, and no items under Universal Windows subtree. enter image description here

Tom Xue
  • 3,169
  • 7
  • 40
  • 77
  • @PavelAnikhouski The original code has that line. As I mentioned I did not change the code, and it cannot work in my environment. – Tom Xue Nov 27 '19 at 10:20
  • Well, it seems the problem is that you are trying to call UWP APIs from regular desktop application – Pavel Anikhouski Nov 27 '19 at 10:20
  • @PavelAnikhouski I just use my VS2019 to open the project code, which I git clone from GitHub. Then how should I do? Thanks! – Tom Xue Nov 27 '19 at 10:22
  • There are two references, `System.Runtime.WindowsRuntime.dll` and `Windows.winmd` You can find them in `HotkeyWindow.csproj` You need to ensure that you have them on your machine or update to actual path. You can also examine the `Universal Windows` subtree in reference manager – Pavel Anikhouski Nov 27 '19 at 10:25
  • @PavelAnikhouski Please check my main post, the last part. I add more info related to your question. – Tom Xue Nov 28 '19 at 02:58

1 Answers1

1

Windows.ApplicationModel does not exist, why?

The problem is you have missed Windows.winmd reference for Desktop App. You could find it with this path C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.xxxxxx.0\Windows.winmd for more please refer this case reply.

If your project has missed Windows Desktop Extension for UWP lib, Please install windows sdk and search it in extension list as you mentioned.

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36