Facing error in the NSB worker, while trying to Load the X509Certificate2 . The same code works well independently, and as a stand alone application. However, errors out within the NSB structure, either as a worker or as a Test console app. The sample code is as follow -
class Program
{
static void Main(string[] args)
{
try
{
string filePath = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory);
filePath = Directory.GetParent(Directory.GetParent(filePath).FullName).FullName;
filePath = Path.Combine(filePath, @"Cert\TestCompany-qa.partner.client.siriusxm.com.pfx");
X509Certificate2 certificate = new X509Certificate2(filePath, "****key****");
SoapMessageHelper soapHelper = new SoapMessageHelper(certificate, @"https://api-ext-test.siriusxm.com/SAT/UpdateDeviceSatRefresh/v_1");
var test = soapHelper.ActivateDevice(new ActivateDeviceRequest()
{
SourceName = "12493",
ESN = "W26890HW",
TimeStamp = DateTime.UtcNow,
TrasanctionId = System.Guid.NewGuid().ToString()
});
XmlDocument doc = new XmlDocument();
doc.LoadXml(test);
foreach (XmlNode node in doc.DocumentElement.ChildNodes)
{
foreach (XmlNode locNode in node)
{
if (locNode.Name == "ns0:responseRefreshDevice")
{
string resultCode = locNode["ns0:resultCode"].InnerText;
string errorCode = locNode["ns0:errorCode"].InnerText;
string errorMessage = locNode["ns0:errorMessage"].InnerText;
Console.WriteLine(resultCode + errorCode + errorMessage);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(
String.Format("Exception occurred{0}Message:{1}{2}Inner Exception: {3}", Environment.NewLine, ex.Message, Environment.NewLine, ex.InnerException));
}
}
}
The error is observed in the line -
X509Certificate2 certificate = new X509Certificate2(filePath, "***key***UeUHFxS");
The exception message being -
System.Security.Cryptography.CryptographicException: 'The system cannot find the file specified.