Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twilio Rest API throws Error: Could not load type 'Twilio.TwilioClient' from assembly 'Twilio, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

Tags:

c#

sms

twilio

This is the code I'm running in a C# ASP.Net Mvc project. The error thrown identifies that it was thrown at the closed curly bracket ( } ).

    public ActionResult SendSms()
    {
        const string accountSid = "ACCOUNT_SID";
        const string authToken = "AUTH_TOKEN"; 
        TwilioClient.Init(accountSid, authToken);

        var to = new PhoneNumber("+NUMBER");
        var from = new PhoneNumber("+NUMBER");

        var message = MessageResource.Create(
            to: to,
            from: from,
            body: "This is a test.");

        return Content(message.Sid);
    }

I have also tried using

TwilioRestClient restClient = new TwilioRestClient(accountSid, authToken);

In place of the TwilioClient.Init(...); command. The same error produces. Here's the error and stack trace:

[TypeLoadException: Could not load type 'Twilio.TwilioClient' from assembly 
'Twilio, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.]
   Twilio.Controllers.SMSController.SendSms() in 
c:\users\crush\Source\Repos\Twilio\Twilio\Controllers\SMSController.cs:34
   lambda_method(Closure , ControllerBase , Object[] ) +61
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, 
Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext     controllerContext, IDictionary`2 parameters) +157
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.<>c.    <BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult,     ActionInvocation innerInvokeState) +22
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
   System.Web.Mvc.Async.AsyncInvocationWithFilters.    <InvokeActionMethodFilterAsynchronouslyRecursive>b__11_0() +50
   System.Web.Mvc.Async.<>c__DisplayClass11_1.    <InvokeActionMethodFilterAsynchronouslyRecursive>b__2() +228
   System.Web.Mvc.Async.<>c__DisplayClass7_0.    <BeginInvokeActionMethodWithFilters>b__1(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult     asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
   System.Web.Mvc.Async.<>c__DisplayClass3_6.<BeginInvokeAction>b__3() +35
   System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__5(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +11
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +45
   System.Web.Mvc.<>c.<BeginExecute>b__151_2(IAsyncResult asyncResult, Controller controller) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +28
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9874329
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +159

What am I doing wrong? I'm using Twilio version 5.13.4, VS 2017, and Windows 8. I also don't see how the message is being sent at all, does the TwilioClient just look for a MessageResource object and send it? Perhaps my misunderstanding of this is why it isn't working, but I followed this tutorial https://www.youtube.com/watch?v=ndxQXnoDIj8 (I assume) accurately and the error still produces. Different c# implementations directly from the Twilio site produce the same error.

UPDATE: I noticed that the version number for Twilio was 5.3.0 in the video and backdated to that, but the same error occurs.

like image 475
Courtney Rush Avatar asked Dec 20 '25 13:12

Courtney Rush


1 Answers

One potential cause is if you name your project "Twilio".

like image 160
user1050483 Avatar answered Dec 22 '25 03:12

user1050483



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!