Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Can't directly convert WinRT.IInspectable to Windows.ApplicationModel.LaunchActivatedEventArgs #5008

Open
Gaoyifei1011 opened this issue Jan 7, 2025 · 0 comments

Comments

@Gaoyifei1011
Copy link

Gaoyifei1011 commented Jan 7, 2025

Description

Bug: Can't directly convert WinRT.IInspectable to Windows.ApplicationModel.LaunchActivatedEventArgs

---------------------------

不能直接将 WinRT.IInspectable 转换为 Windows.ApplicationModel.LaunchActivatedEventArgs

Steps To Reproduce

  1. Create a new desktop bridge project, and add a desktop application.
  2. Define the app execution alias AppExceutionAlias in the app manifest package.appxmanifest
  3. Try to start the app in the console, the Windows.ApplicationModel.AppInstance.GetActivatedEventArgs method directly returns null
  4. When you call the corresponding Microsoft.Windows.AppLifecycle.AppInstance.GetActivatedEventArgs method of the Windows App SDK, it is directly returned in the Windows.ApplicationModel.AppInstance.GetActivatedEventArgs method null is further wrapped to force the creation of a new LaunchActivatedEventArgs class, and the GetCommandLine function is added to retrieve the command-line string of the current process, and the final return is ExtendedActivationKind.Launch.
  5. In the desktop bridge app, when you try to call the Windows App SDK Microsoft.Windows.AppLifecycle.AppInstance.GetActivatedEventArgs method, an AppActivationArguments object is returned with a Data property of an object, When debugging, it is displayed as WinRT.IInspectable. You can call GetRunTimeClassName to get a type of Windows.ApplicationModel.ILaunchActivatedEventArgs.
  6. At this time, if the as extension method of winrt is called, the InvaildCastException exception will occur, and the .NET as keyword will return null
  7. If you call LaunchActivatedEventArgs.FromAbi((activationArguments.Data as IInspectable).ThisPtr) method will return LaunchActivatedEventArgs
---------------------------

1.创建新桌面桥项目,并添加桌面应用程序。
2.在应用清单 Package.appxmanifest 中定义应用执行别名 AppExceutionAlias
3.在控制台尝试启动应用,Windows.ApplicationModel.AppInstance.GetActivatedEventArgs 方法直接返回 null
4.调用 Windows App SDK 相应的 Microsoft.Windows.AppLifecycle.AppInstance.GetActivatedEventArgs 方法时,会在 Windows.ApplicationModel.AppInstance.GetActivatedEventArgs 方法直接返回 null 的基础上做进一步包装,直接强制创建一个新的 LaunchActivatedEventArgs 类,并添加 GetCommandLine 函数检索当前进程的命令行字符串,最终返回的 ActivationKindExtendedActivationKind.Launch
5.在桌面桥应用中,尝试调用 Windows App SDK Microsoft.Windows.AppLifecycle.AppInstance.GetActivatedEventArgs 方法时,会返回 AppActivationArguments 对象,Data 属性为 object,调试时显示成 WinRT.IInspectable。可以调用 GetRunTimeClassName 获取的类型为 Windows.ApplicationModel.ILaunchActivatedEventArgs
6.这时如果调用winrt的as扩展方法,会发生 InvaildCastException 异常,.NET as 关键字返回 null
7.如果调用 LaunchActivatedEventArgs.FromAbi((activationArguments.Data as IInspectable).ThisPtr) 方法就能正常返回 LaunchActivatedEventArgs

Image
Image
Image
Image
https://github.com/microsoft/WindowsAppSDK/blob/main/dev/AppLifecycle/AppInstance.cpp#L544

Expected Behavior

In the case of Windows.ApplicationModel.AppInstance.GetActivatedEventArgs returns null, the Windows App SDK's Microsoft.Windows.AppLifecycle.AppInstance.GetActivatedEventArgs returns The Data property of the AppActivationArguments object (shown as an object class in .NET) is no longer of type IInspectable, but Windows.ApplicationModel.AppInstance.LaunchActivatedEventArgs

Windows.ApplicationModel.AppInstance.GetActivatedEventArgs 返回 null 的情况下,Windows App SDK 的 Microsoft.Windows.AppLifecycle.AppInstance.GetActivatedEventArgs 返回的 AppActivationArguments 对象的 Data 属性(.NET 中显示为 object 类),不再是 IInspectable 类型,而是 Windows.ApplicationModel.AppInstance.LaunchActivatedEventArgs

Version Info

Windows App SDK 1.6.241114003
CsWinRT 2.2.0
.NET 9

Additional Context

No response

@Gaoyifei1011 Gaoyifei1011 changed the title Bug: Can't directly to WinRT.IInspectable into Windows.ApplicationModel.LaunchActivatedEventArgs Bug: Can't directly convert WinRT.IInspectable to Windows.ApplicationModel.LaunchActivatedEventArgs Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant