Search code examples
c#.netvisual-studiouwpdesktop-bridge

FullTrustProcessLauncher in IBackgroundTask not working


I am trying to launch a FullTrustProcess from my Background task. For this I am calling await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();, but it tells me FullTrustProcessLauncher does not exist in this context. I have tried adding Windows Desktop Extensions for the UWP and Windows.ApplicationModel.FullTrustAppContract references to my Background task, but then I am not able to compile it for release (Unless I disable .Net native toolchain). The error I then get is: Internal compiler error: An item with the same key has already been added.

How can I fix this? My background task needs to somehow launch the WPF component. Is there a workaround, like launching a UWP foreground app without a window? Or do I have an import/permission wrong? Note that I only seem to need to add one of the references, but with both it does not work.


Solution

  • You just need to add this as reference to the project that implements the background task: enter image description here

    Then you will find the FullTrustProcessLauncher APIs in the Windows.ApplicationModel namespace. Also make sure the component is a "Windows Runtime Component", not a "Class Library". If this doesn't work, please share a repro project that demonstrates the problem. It has worked for me in my projects.