I'm working on a task and wanted to find a certificate from the Local Computer store based on its Thumbprint and ran into the below exception. If you are trying something similar you might get the below exception if you COPY the value from the Certificate MMC snap in.

System.FormatException: Invalid hexadecimal string format.


at System.IdentityModel.SecurityUtils.DecodeHexString(String hexString)

at System.IdentityModel.Selectors.X509CertificateStore.Find(X509FindType findType, Object findValue, Boolean validOnly)

at System.ServiceModel.Security.SecurityUtils.GetCertificateFromStoreCore(StoreName storeName, StoreLocation storeLocation, X509FindType findType, Object findValue, EndpointAddress target, Boolean throwIfMultipleOrNoMatch)
at System.ServiceModel.Security.SecurityUtils.GetCertificateFromStore(StoreName storeName, StoreLocation storeLocation, X509FindType findType, Object findValue, EndpointAddress target)
at System.ServiceModel.Configuration.X509RecipientCertificateServiceElement.ApplyConfiguration(X509CertificateRecipientServiceCredential cert)
at System.ServiceModel.Configuration.ServiceCredentialsElement.ApplyConfiguration(ServiceCredentials behavior)
at System.ServiceModel.Configuration.ServiceCredentialsElement.CreateBehavior()
at System.ServiceModel.Description.ConfigLoader.LoadBehaviors[T](ServiceModelExtensionCollectionElement`1 behaviorElement, KeyedByTypeCollection`1 behaviors, Boolean commonBehaviors)
at System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress, Boolean skipHost)
at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection)
at System.ServiceModel.ServiceHost.ApplyConfiguration()
at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)


When you copy the Thumbnail / Serial values of a certificate an extra character gets copied, you need to remove this when pasting. Here it is in Notepad2 and the source where I copied it from:


You can see the "?" in the green square, copy everything after that or type it manually and the value should be parsed properly.

Could have done without wasting time debugging that.