question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WPF + .Net 5 + WinRT APIs not yet functional

See original GitHub issue

Problem description:

Critical WinRT APIs when consumed from a WPF .Net 5 app are not yet functional. One example

                Progress<DeploymentProgress> progressCallback = new Progress<DeploymentProgress>((op) =>
                {
                    //var appxProgress = new AppxProgress(op.percentage, "...");
                    //progress.Report(appxProgress);
                });

                var pkgManager = new PackageManager();

                // MP! fixme: why do we hang on the await on occasion?
                Debug.WriteLine("Installing package ...");
                DeploymentResult result = await pkgManager.AddPackageAsync(uriToAppx, urisToDependencies, DeploymentOptions.ForceTargetApplicationShutdown).AsTask(progressCallback).WaitOrCancel(stop);
                Debug.WriteLine("Package installed ...");

After commenting out the UI update portion of the code, AddPackageAsync still hangs. If I remove the use of DeploymentProgress, AddPackageAsync always completes.

Actual behavior:

Call hangs.

Expected behavior:

Call should complete.

Minimal repro:

Shown above. You can remove the WaitOrCancel() bit for your testing. It’s there only to support cancellation, which happens to work even when the call is hung.

The repo that contains a “working” solution is located here: https://github.com/Noemata/AppxInstaller

The call hangs about 50% of the time. So it works 50% of the time when re-run the app. 😦

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ryalanmscommented, Jan 29, 2021

I tagged him so he could comment. This looks like a CsWinRT issue.

0reactions
Noematacommented, Feb 1, 2021

@AaronRobinsonMSFT , if you looked at the provided repos (https://github.com/Noemata/AppxInstaller.Core versus https://github.com/Noemata/AppxInstaller), you would agree that in this specific case with the API mix that is at play, the two (.NET 3.1 and .NET 5) should have exactly the same behavior when creating a self contained executable. The fact that both .NET 5 and .NET Core 3.1 work exactly the same way when a self contained executable isn’t being created only emphasizes the point that there is an issue with .NET 5!

As for your “intentional breaking change”, that is grief Microsoft keeps hoisting on both itself and the users of its products… Adding “may not be a priority to bring back”, isn’t relevant here because this is an apples to apples comparison. You just need to take the time to look at the two sample projects. They are equivalent in every respect and introduce nothing that hasn’t been promised or promoted as working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Windows Runtime APIs not supported in desktop apps
This article describes WinRT APIs that aren't supported for use in desktop apps, or that have restrictions.
Read more >
Calling Windows APIs in .NET5 - Windows Developer Blog
NET developers to access the set of Windows Runtime (WinRT) APIs that are shipped as part of Windows. .NET5 applications can now access...
Read more >
c# - Use WinRT API in netstandard2.0 library referenced by ...
Windows ) . If I now use this library from net5.0 and execute the part using WinRT I get the following exception (executed...
Read more >
New .NET 5 Windows TFM's explained - Andrew Leader
If you're writing a WPF app and want to use .NET 5 plus access the Windows 10 WinRT APIs (like geolocation, etc), there's...
Read more >
Windows APIs Everywhere in .NET - YouTube
NET applications by taking advantage of the native platform APIs in Windows. ... by making access to both WinRT and Win32 APIs easy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found