Autoscaling: problem with getting certificate

Topics: Building and extending application blocks
Jul 26, 2012 at 8:54 AM

hey.

i'm trying to write a simple console application which uses autoscaling app block to scale my application in the cloud.

i set the app.config and the rules.xml and services.xml as shown in the lab

but each time i run i get the error:

The certificate with thumbprint 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' in store name 'My' and store location 'CurrentUser' could not be found.

 i re installed the certificate several times. the certificate is o.k

when i check it with the following method it finds it:

 private static X509Certificate2 FindCertificate(string certificateName, StoreName storeName, StoreLocation storeLocation)
        {

            X509Store store = new X509Store(storeName, storeLocation);
            X509Certificate2 certificate = null;
            try
            {
                store.Open(OpenFlags.MaxAllowed);
                X509Certificate2Collection collection = store.Certificates.Find(X509FindType.FindByThumbprint, certificateName, false);

                if (collection.Count > 0)
                    certificate = collection[0];
                else
                    throw new Exception(string.Format("CertificateNotFound {0}", certificateName));
            }
            finally
            {
                store.Close();
            }

            return certificate;
        }

 but when i run the autoscaling it always fails.

i used the reflector to try and see what is the problem but i just see that in :

public static class CertificateHelper
    {
        public static X509Certificate2 FindCertificate(StoreName certificateStoreName, StoreLocation certificateStoreLocation, string certificateThumbprint, bool withPrivateKey, bool validOnly)
        {
            X509Certificate2Collection certificates;
            Guard.ArgumentNotNullOrEmpty(certificateThumbprint, "certificateThumbprint");
            X509Store store = null;
            try
            {
                store = new X509Store(certificateStoreName, certificateStoreLocation);
                store.Open(OpenFlags.ReadOnly);
                certificates = store.Certificates.Find(X509FindType.FindByThumbprint, certificateThumbprint, validOnly);
            }
            catch (Exception exception)
            {
                throw new CertificateException(string.Format(CultureInfo.CurrentCulture, Resources.CertificateCouldNotBeRetrievedExceptionMessage, new object[] { certificateThumbprint, certificateStoreName, certificateStoreLocation }), exception);
            }
            finally
            {
                if (store != null)
                {
                    store.Close();
                }
            }
            if (certificates.Count < 1)
            {
                throw new CertificateException(string.Format(CultureInfo.CurrentCulture, validOnly ? Resources.ValidOnlyCertificateNotFoundExceptionMessage : Resources.CertificateNotFoundExceptionMessage, new object[] { certificateThumbprint, certificateStoreName, certificateStoreLocation }));
            }
            X509Certificate2 certificate = certificates[0];
            if (withPrivateKey && !certificate.HasPrivateKey)
            {
                throw new CertificateException(string.Format(CultureInfo.CurrentCulture, Resources.CertificateHasNoPrivateKeyExceptionMessage, new object[] { certificateThumbprint, certificateStoreName, certificateStoreLocation }));
            }
            return certificate;
        }
    }

it return Certificate.Count == 0 and then throws the exception.

i have no idea why it can't find it

i'm really frustrated

any help would be appriciated...

Jul 27, 2012 at 6:26 AM

That's very strange.  I just wanted to verify that the thumbprint in the exception is the same thumbprint that is in the services.xml configuration file (as well as the correct thumbprint of the certificate).  Can you post the services.xml file that you are using?

I'm wondering if it could be a permission problem?  Are you running the autoscaling app and your cert test application under the same user?

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Jul 27, 2012 at 12:48 PM

yes, i run the test method from the main function of th autoscaling app.

But I just solved the problem!!! apparently when I copied the thumbprint from the certificate there was an invisible character hiding somewhere in the string

so i just copied the string from the test method,and No It works!

Cheers!

Thanks anyway for trying to help.

btw, this "autoscaling block" is really cool thing and really helps us!