UWP can't get certificates when choose 'CurrentUser'

Huang, Jiang 41 Reputation points
2021-10-27T03:11:21.86+00:00

I wanna get certificates in a UWP project. As the following link
https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.x509certificate2ui.selectfromcollection?redirectedfrom=MSDN&view=windowsdesktop-5.0#overloads
Because UWP doesn't have the 'X509Certificate2UI', so I write UI myself. But still has a problem

the code below

X509Store store = new X509Store("MY",StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;

works well in a WPF project, the 'collection' has about 600 certificates,
but in a UWP project, 'collection' has 0 certificate.

if I change 'StoreLocation.CurrentUser' to 'StoreLocation.LocalMachine' in first line,
the results of 'collection' in WPF and UWP are the same

Don't know why? Are there some problems in my environment?

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,851 Reputation points
    2021-10-27T07:54:12.877+00:00

    Hello,
    Welcome to Microsoft Q&A!

    Please open app's appxmanifest file and find Capabilities option, check if enable Shared User Certificates option. The sharedUserCertificates capability enables an app to add and access software and hardware-based certificates in the Shared User store. For more info please refer to App capability declarations document

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful