0

I have a NetCore3.1 WPF Application (Windows 10, VS2019). I can pack it as MSIX app (using official documentation). In the .appxmanifest file I added:

<Capabilities>
  <Capability Name="internetClient" />
  <rescap:Capability Name="runFullTrust" />
  <rescap:Capability Name="packageQuery" />
</Capabilities>

I can install and use my application without problems. The problem is that I try to use the Windows.Management API in my application like so:

var pkgManager = new Windows.Management.Deployment.PackageManager();
IEnumerable<Windows.ApplicationModel.Package> packages = pkgManager.FindPackagesForUser("");

I dont get any exceptions when using this but the packages variable value is System.__ComObject.

I dont understand what exactly is that and why am I not getting the desired result - a list of all installed msix packages for the user.

IInspectable
  • 46,945
  • 8
  • 85
  • 181

1 Answers1

0

I managed to (sort of) solve my problem.

I still have no idea why is my packages variable System.__ObjectCom and what exactly is System.__ObjectCom but it seems that if one treats this object as the supposed-to-be object (in my case IEnumerable<Windows.ApplicationModel.Package>) its ok.

So basically, the following produced something (much to my surprise):

    IEnumerable<Windows.ApplicationModel.Package> packages = pkgManager.FindPackagesForUser("");
    List<string> installedAppsDisplayNAme = new List<string>();
    foreach (var package in packages)
    {
        installedAppsDisplayNAme.Add(package.DisplayName);
    }
  • `System.__ObjectCom` is presumably .NET Core's representation of a [COM object](https://learn.microsoft.com/en-us/windows/win32/com/component-object-model--com--portal). One feature of COM objects is that they support runtime reflection. If you are requesting an interface (like `IEnumerable`) the object in question knows whether it implements that interface. If it doesn't, it returns an error code that surfaces as an exception in C#. If it does everything goes as expected. Either way the operation is safe. – IInspectable Mar 05 '21 at 19:54
  • I am glad you have got your solution and thanks for your sharing, I would appreciate it if you mark them as answer and this will be beneficial to other community. – Zeus Mar 08 '21 at 05:11