2

I have app that supports ShareTarget to upload files to cloud. Everything works great when I my app is closed (and I mean closed - not hibernated or something like this) - I choose share photo and everyting goes as expected. But when I open the app, then exit (app stays hibernated in memory) and try to share something on line

Window.Current.Activate();

I get

Exception thrown: 'System.InvalidCastException' in mscorlib.ni.dll
Message "Unable to cast COM object of type 'System.ComponentModel.PropertyChangedEventHandler' to class type 'System.ComponentModel.PropertyChangedEventHandler'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface."

Then my app closes completely and second try is success. Whole onShareTarget code:

protected override void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
{
    if (!args.ShareOperation.Data.Contains(
        Windows.ApplicationModel.DataTransfer.StandardDataFormats.StorageItems))
        return;
    AppShell shell = Window.Current.Content as AppShell;
    if (shell == null)
        shell = new AppShell();
    Window.Current.Content = shell;
    shell.AppFrame.Navigate(typeof(ChooseFolderPage), args.ShareOperation);
    Window.Current.Activate();
}

Any ideas how to fix it?

Piachu
  • 195
  • 1
  • 13
  • Tested your code, it works fine by my side, at least there is no problem with your posted code. I think your problem is possible with your AppShell.xaml.cs code, could you please post the code of `PropertyChangedEventHandler`? And there is a similar question [InvalidCastException with share target on Windows 8](http://stackoverflow.com/questions/12326069/invalidcastexception-with-share-target-on-windows-8), you can check if the answer there works with you. – Grace Feng Mar 01 '16 at 07:47
  • Just wondering - are you using Caliburn.Micro framework? – Sevenate Aug 04 '16 at 20:16
  • I am also getting the same issue, Additional information: Unable to cast COM object of type 'System.ComponentModel.PropertyChangedEventHandler' to class type 'System.ComponentModel.PropertyChangedEventHandler'. Instances of types that represent COM components cannot be cast to types that do not – Suresh Balaraman Feb 22 '17 at 12:02

0 Answers0