Skip to content

Windows AI APIs do not work in x64 Apps packaged with external location #6308

Description

@ULTRON-MARK

Describe the bug

I want to use Windows AI APIs in my x64 desktop app, so I need a package identity. I chose to Grant package identity by packaging with external location, but I found that it cannot run and throws an ERROR_BAD_EXE_FORMAT exception. However, arm64 programs work fine (Perhaps it's because my computer uses the arm64 architecture). In addition, packaged Apps work fine for both arm64 and x64 architectures.

Steps to reproduce the bug

  1. In Visual Studio, create a new C++ console application project.
  2. Install Nuget package: Microsoft.WindowsAppSDK, Microsoft.Windows.CppWinRT.
  3. Follow this tutorial to grant package identity by manually packaging with an external location.
  4. Write a simple Demo code:
#include <iostream>
#include <winrt/Microsoft.Graphics.Imaging.h>
#include <winrt/Microsoft.Windows.AI.Imaging.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Graphics.Imaging.h>
#include <winrt/Windows.Storage.Streams.h>

bool IsTextRecognizerReady() {
  using namespace winrt::Microsoft::Windows::AI;
  auto ready_state = Imaging::TextRecognizer::GetReadyState();
  if (ready_state == AIFeatureReadyState::Ready ||
      ready_state == AIFeatureReadyState::NotReady) {
    if (ready_state == AIFeatureReadyState::NotReady) {
      auto result = Imaging::TextRecognizer::EnsureReadyAsync().get();
      if (result.Status() != AIFeatureReadyResultState::Success) {
        return false;
      }
    }
  } else {
    return false;
  }
  return true;
}

int main() {
  if (IsTextRecognizerReady()) {
    std::cout << "TextRecognizer is ready." << std::endl;
  } else {
    std::cout << "TextRecognizer is not ready" << std::endl;
  }
  getchar();
}
  1. Select Solution Platform as x64, then compile and launch the application.

Expected behavior

It runs normally without throwing any exceptions.

Screenshots

The image below is a screenshot of the application running with the Solution Platform set to arm64:
Image

However, an exception is thrown when set to x64, as shown in the image below:

Image

NuGet package version

Windows App SDK 1.8.5: 1.8.260209005

Packaging type

Unpackaged

Windows version

Insider Build (xxxxx)

IDE

Visual Studio 2022

Additional context

  • Device: Microsoft Surface Laptop, 7th Edition
  • OS: Windows Insider Preview, 25H2 (26220.8062)
  • CPU: Snapdragon(R) X 12-core X1E80100 @ 3.40 GHz (3.42 GHz)
  • NPU: Snapdragon(R) X Elite - X1E80100 - Qualcomm(R) Hexagon(TM) NPU

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-PackagingTopics related to packaging behavior of Windows App SDK

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions