You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a new desktop bridge project, and add a desktop application.
Define the app execution alias AppExceutionAlias in the app manifest package.appxmanifest
Try to start the app in the console, the Windows.ApplicationModel.AppInstance.GetActivatedEventArgs method directly returns null
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.
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.
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
If you call LaunchActivatedEventArgs.FromAbi((activationArguments.Data as IInspectable).ThisPtr) method will return LaunchActivatedEventArgs
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
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
Description
Bug: Can't directly convert WinRT.IInspectable to Windows.ApplicationModel.LaunchActivatedEventArgs
---------------------------
不能直接将 WinRT.IInspectable 转换为 Windows.ApplicationModel.LaunchActivatedEventArgs
Steps To Reproduce
AppExceutionAlias
in the app manifestpackage.appxmanifest
Windows.ApplicationModel.AppInstance.GetActivatedEventArgs
method directly returnsnull
Microsoft.Windows.AppLifecycle.AppInstance.GetActivatedEventArgs
method of the Windows App SDK, it is directly returned in theWindows.ApplicationModel.AppInstance.GetActivatedEventArgs
method null is further wrapped to force the creation of a newLaunchActivatedEventArgs
class, and theGetCommandLine
function is added to retrieve the command-line string of the current process, and the final return isExtendedActivationKind.Launch
.Windows App SDK Microsoft.Windows.AppLifecycle.AppInstance.GetActivatedEventArgs
method, anAppActivationArguments
object is returned with aData
property of an object, When debugging, it is displayed asWinRT.IInspectable
. You can callGetRunTimeClassName
to get a type ofWindows.ApplicationModel.ILaunchActivatedEventArgs
.InvaildCastException
exception will occur, and the .NETas
keyword will returnnull
LaunchActivatedEventArgs.FromAbi((activationArguments.Data as IInspectable).ThisPtr)
method will returnLaunchActivatedEventArgs
---------------------------
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
函数检索当前进程的命令行字符串,最终返回的ActivationKind
为ExtendedActivationKind.Launch
。5.在桌面桥应用中,尝试调用 Windows App SDK
Microsoft.Windows.AppLifecycle.AppInstance.GetActivatedEventArgs
方法时,会返回AppActivationArguments
对象,Data
属性为object
,调试时显示成WinRT.IInspectable
。可以调用GetRunTimeClassName
获取的类型为Windows.ApplicationModel.ILaunchActivatedEventArgs
。6.这时如果调用winrt的as扩展方法,会发生
InvaildCastException
异常,.NETas
关键字返回null
7.如果调用
LaunchActivatedEventArgs.FromAbi((activationArguments.Data as IInspectable).ThisPtr)
方法就能正常返回LaunchActivatedEventArgs
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'sMicrosoft.Windows.AppLifecycle.AppInstance.GetActivatedEventArgs
returns TheData
property of theAppActivationArguments
object (shown as an object class in .NET) is no longer of typeIInspectable
, butWindows.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
The text was updated successfully, but these errors were encountered: