作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我在 C# ASP.Net Mvc 项目中运行的代码。抛出的错误表明它是在闭花括号 ( } ) 处抛出的。
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);
}
我也尝试过使用
TwilioRestClient restClient = new TwilioRestClient(accountSid, authToken);
代替 TwilioClient.Init(...);命令。产生同样的错误。这是错误和堆栈跟踪:
[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
我做错了什么?我使用的是 Twilio 版本 5.13.4、VS 2017 和 Windows 8。我也根本不知道消息是如何发送的,TwilioClient 是否只是查找 MessageResource 对象并发送它?也许我对此的误解是它不起作用的原因,但我遵循了本教程https://www.youtube.com/watch?v=ndxQXnoDIj8 (我假设)准确,但错误仍然产生。直接来自 Twilio 站点的不同 C# 实现会产生相同的错误。
更新:我注意到视频中 Twilio 的版本号是 5.3.0,并回溯到该版本,但出现了相同的错误。
最佳答案
一个潜在的原因是您将项目命名为“Twilio”。
关于c# - Twilio Rest API 抛出错误 : Could not load type 'Twilio.TwilioClient' from assembly 'Twilio, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50969874/
我是一名优秀的程序员,十分优秀!