Forum Xamarin.Android


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How to add a self-signed certificate to TrustedPeople in Xamarin.Android

I have the following code to add a generated self-signed certificate to the certificate store:

    StorePermission sp = new StorePermission(PermissionState.Unrestricted);
    sp.Flags = StorePermissionFlags.AllFlags;
    StoreName storeName = StoreName.TrustedPeople;
    StoreLocation storeLocation = StoreLocation.CurrentUser;
    X509Store store = new X509Store(storeName, storeLocation);
    Console.WriteLine($"Cert count: {store.Certificates.Count}");
    //store.AddRange(new X509Certificate2Collection(cert));
    Console.WriteLine($"Cert count: {store.Certificates.Count}");
  catch (Exception ex)

It resided in a .Net Standard libray and works flawlessly with a console application.

I intend to use it with a Xamarin.Android project. The code runs, but it does nothing, the Count value remains the same after the Add method.

This is what I see on the output:

I/mono-stdout(18830): Cert count: 1
Cert count: 1
D/Mono    (18830): DllImport searching in: 'libmono-btls-shared' ('./').
D/Mono    (18830): Searching for 'mono_btls_x509_cmp'.
D/Mono    (18830): Probing 'mono_btls_x509_cmp'.
D/Mono    (18830): Found as 'mono_btls_x509_cmp'.
The thread 0x16d0 has exited with code 0 (0x0).
Cert count: 1
I/mono-stdout(18830): Cert count: 1

What permission/method should I use to add it to the Android cert store?



  • robbitrobbit CNMember Xamurai

    Please show more detail error logs.

  • AndrasVAndrasV Member

    There is no error, so I can't provide error logs.

    It also seems that this code can't actually work as there is no implicit certification adding, it must be added by user interaction, see this

  • thirdeyesthirdeyes Member

    Hi , is this problem got a solution? Thank you. I'm facing the same issue.

Sign In or Register to comment.