C# ShareTarget[Windows 10 UWP]上的InvalidCastException
我有一个支持ShareTarget将文件上传到云的应用程序。当我关闭我的应用程序时,一切都很好(我的意思是关闭-不是休眠或类似的东西)-我选择共享照片,一切都按预期进行。但当我打开应用程序,然后退出(应用程序在内存中处于休眠状态)并尝试在线共享某些内容C# ShareTarget[Windows 10 UWP]上的InvalidCastException,c#,win-universal-app,windows-10-universal,C#,Win Universal App,Windows 10 Universal,我有一个支持ShareTarget将文件上传到云的应用程序。当我关闭我的应用程序时,一切都很好(我的意思是关闭-不是休眠或类似的东西)-我选择共享照片,一切都按预期进行。但当我打开应用程序,然后退出(应用程序在内存中处于休眠状态)并尝试在线共享某些内容 Window.Current.Activate(); 我明白了 Exception thrown: 'System.InvalidCastException' in mscorlib.ni.dll Message "Unable to cast
Window.Current.Activate();
我明白了
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."
然后我的应用程序完全关闭,第二次尝试成功。整个onShareTarget代码:
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();
}
有什么办法可以修复吗?测试了你的代码,在我这方面效果很好,至少你发布的代码没有问题。我认为您的AppShell.xaml.cs代码可能存在问题,请您发布
PropertyChangedEventHandler
的代码好吗?还有一个类似的问题,你可以检查答案是否对你有效。只是想知道-你在使用Caliburn.Micro framework吗?我也遇到了同样的问题,其他信息:无法将类型为“System.ComponentModel.PropertyChangedEventHandler”的COM对象强制转换为类型为“System.ComponentModel.PropertyChangedEventHandler”的类。表示COM组件的类型的实例不能强制转换为不表示COM组件的类型