Share targets + existing apps

2

I have an app that's built on UWP in C#. It is a share target for a few types - photos, URLs, text. When ran in isolation, those share contracts work just fine. However, if the app was already running when the share target is activated, things become unpredictable.

MSDN states that existing instances are terminated when you open a share contract https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh871367.aspx:

“Note
If your app is running when it is activated as a Share target, the existing instance of your app is terminated and a new instance of your app is launched to handle the contract”

However this is not the case, the existing app keeps on running and a new "Window" within that instance of the app is created for the share contract.

Things hum along until you get to the end. After calling ShareOperation.ReportCompleted(), the share window closes like you'd expect. The existing app starts acting unpredictably. Sometimes it just works. Other times, you'll see native exceptions such as:

Unhandled exception at 0x70B8468B (ucrtbase.dll) Fatal program exit requested.

Or, you'll see one of a handful of managed exceptions:

Exception thrown: 'System.Runtime.InteropServices.InvalidComObjectException' Additional information: COM object that has been separated from its underlying RCW cannot be used. or The operation cannot be completed because the window is being closed. (Exception from HRESULT: 0x802A0201)

or

The operation cannot be completed because the window is being closed. (Exception from HRESULT: 0x802A0201)

After one of these exceptions, the application crashes and quits. The exceptions sometimes occur immediately, but sometimes they won't happen until you actually click on the existing app and re-focus it.

Any idea why this happens? I'm hoping we're just doing something wrong that we can fix, but we're not doing anything outlandish. We handle the share data and call ReportCompleted.

c#
.net
win-universal-app
asked on Stack Overflow Feb 25, 2016 by Deeko

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0