Twilio causes MT4 crash

 

I am trying to connect Metatrader4 with Twilio (voice and messaging service), via DLL. The call goes something like this:

MT4 expert script -> C++/CLI DLL -> C# DLL -> Twilio

I have successfully tested both dlls using a (C#) console application - the program calls my mobile successfully. However when I try to run the MT4 script, although the call goes through I get an UnhandledException error 0xE0434352 and any subsequent calls are not made. I have sucessfully tested other functions in the dlls that pass numeric and string data - successfully.

I have narrowed the problem line down to the Twilio call CallResource.Create(...). Metatrader uses Unicode strings, but as I said, I can receive strings back no problem. My machine is Winx64. The C# dll code has a try-catch block, but no further information comes out at the time the mt4 script stops.

This problem has me stumped. Any ideas?


        try
        {
            TwilioClient.Init(accountSid, authToken);
            PhoneNumber toNo = new PhoneNumber("+**********");

            string url = "http://demo.twilio.com/docs/voice.xml";
            Uri myURI = new Uri(url);

            CallResource call = CallResource.Create(toNo, fromNo, url: myURI);

            string callDtls = "Call SID: " + call.Sid + ". Status: " + call.Status.ToString();
            //Console.WriteLine(callDtls);

            resultStr = callDtls + ". Message: " + mesg;

            return resultStr;
        }
        catch (ApiException ex)
        {
            //Console.WriteLine(ex.Message);
            //Console.WriteLine($"Twilio Error {ex.Code} - {ex.MoreInfo}");
            resultStr = ex.Message + " " + ex.MoreInfo + " " + ex.InnerException;
            return resultStr;
        }


Reason: