Search code examples
desktop-bridge

Using Microsoft.Windows.SDK.Contracts, Getting error "Problem generating manifest....An attempt was made to load a program with an incorrect format"


I'm working on VSTO (WinForm) application. I want to use LaunchUriAsync() to launch a second packaged desktop app. I've been trying to get the right references into the VSTO project to allow for the call to Windows.System.Launcher.LauncherUriAsync().

I've followed various guidance. I tried following the guidance to enable UWP APIs in desktop apps.

I also tried the new Microsoft.Windows.SDK.Contracts.

In each case, I can bring in using Windows.System; and I can correctly reference LaunchUriAsync().

Now, when I build, I'm getting errors on every winmd file in the references.

The error is: Problem generating manifest. Could not load file or assembly filename. An attempt was made to load a program with an incorrect format.

I've tried setting the local copy property in each winmd file to false, but I get the same error.


Solution

  • Not all UWP APIs are allowed to be called from any desktop app. You need to follow the process to determine whether an API you want to call from your desktop application is supported.

    Then, if you check the Launcher class, the DualApiPartition attribute is not listed, the API does need the calling app to have a package identity. Therefore a WPF, Windows Forms, or Win32 app is not allowed to call the API unless the app has been converted to a UWP app.