Bit of long shot this one, I am trying to access a REST API from Sage CRM using the SageCRM.Net extensions. I'm using HttpClient and PostAsync() to call the REST API. It looks something like this :
private async Task<(bool success, string errorMessage)> Upload()
{
//set up login details
var login = new Login
{
//email address
Key = "[email protected]",
//password
Secret = "password"
};
var json = JsonConvert.SerializeObject(login);
var data = new StringContent(json, Encoding.UTF8, "application/json");
//login to system
try
{
var client = new HttpClient();
var response = await client.PostAsync("">myrestservice.co.uk/.../login", data);
}
catch (ThreadAbortException ex)
{
return (false, ex.Message);
}
catch (Exception ex)
{
return (false, ex.Message);
}
Its failing on the await client.PostAsync("">myrestservice.co.uk/.../login", data); line with a "Thread was being aborted." exception. My code runs fine if I put it in a console application but as soon as I put it in the SageCRM.Net dll I am building I am always getting this "Thread was being aborted" exception when I attempt to call PostAsync().
Its the first time I have tried using PostAsync() in a Sage CRM dll and I was wondering if anyone else has had any success with this or if there is something I need to do in my DLL to stop the "Thread was being aborted" exception ?