Share via

Exception on getting PackageId

Heiko 1,311 Reputation points
2021-11-22T15:37:35.587+00:00

I have a WPF app that I have converted to a bridge app. In this app I want to offer the user a function to open any installed store app in the store. For this I need the ProductId of an app to create the following url:

ms-windows-store://pdp/?productid=<ProductId>

I have tried the following. Unfortunately I get an InvalidCastException when accessing Package.Id.

PackageId packId = AppInfo.GetFromAppUserModelId("Microsoft.3DBuilder_8wekyb3d8bbwe!App").Package.Id;
string productId = packId.ProductId;

System.InvalidCastException in mscorelib:

The object of type "Windows.ApplicationModel.PackageId" cannot be converted to type "Windows.ApplicationModel.IPackageIdWithMetadata".

at System.StubHelpers.StubHelpers.GetCOMIPFromRCW_WinRT(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget)
at Windows.ApplicationModel.PackageId.get_ProductId()

Is there possibly another way to get the ProductId of any application?

Developer technologies | Universal Windows Platform (UWP)
Developer technologies | Windows Presentation Foundation

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.