This issue first started cropping up when I tried to implement the SendGrid API in my application. I was getting null reference exceptions thrown up by mscorlib.dll anytime I tried to send a message.
In the end I tried to implement the functionality I needed using System.Net.Http.HttpClient resulting in the following test function:
public async System.Threading.Tasks.Task mySendGridFunction(SendGridMessage message)
{
HttpClient client = new HttpClient();
var requestContent = new FormUrlEncodedContent(new[]{
new KeyValuePair<string, string>("api_user", "XXXXXXXXX"),
new KeyValuePair<string, string>("api_key", "XXXXXXXX"),
new KeyValuePair<string, string>("to", "shocklanced@gmail.com"),
new KeyValuePair<string, string>("subject", "STEP-A Summary"),
new KeyValuePair<string, string>("text", "Test Mail"),
new KeyValuePair<string, string>("from", "davidrtye@gmail.com"),
new KeyValuePair<string, string>("fromname", "STEP-A Automated Message"),
});
HttpResponseMessage response = await client.PostAsync("https://api.sendgrid.com/api/mail.send.xml", requestContent);
HttpContent responseContent = response.Content; /*For Debugging purposes*/
}
When I call the PostAsync() function I get a null exception thrown in System.Web.dll followed by mscorlib.dll if I try to continue.
I can't find any other instances of this happening, so I assume there must be something happening on my end that I'm missing, but I can't work out what.
Edit
As requested, here are the screenshots for the Error, and stack trace
Edit 2 The code appears to be working, but the response from the sendgrid service is somehow generating a null reference exception deep in mscorlib.dll. I don't have time to really dig into this for now, so I will just try to manage the issue as best I can without fixing it.
Sometimes it is actually able to pass a response out of the call to PostAsync, but not often